C# 中 C++ const size_t 的等效项是什么?

2023-12-30

我正在尝试将一些 Ogre 代码转换为 C# 版本,但遇到了一个问题:

    const size_t nVertices = 8;
    const size_t vbufCount = 3*2*nVertices;

    float vertices[vbufCount] = {
            -100.0,100.0,-100.0,        //0 position
            -sqrt13,sqrt13,-sqrt13,     //0 normal
            //... 
           -sqrt13,-sqrt13,sqrt13,     //7 normal
    };

基本上,C# 中不存在 const size_t,并且 const int 不能用于声明数组的大小。

我想知道如何声明具有常量值的数组?


size_t 是一个 typedef (有点像 #define 宏),它基本上是另一种类型的别名。它的定义取决于SDK,但通常是无符号整数.

不管怎样,在这种情况下,这并不重要,因为它们是常量,所以您知道 nVertices 是 8,vbufCount 是 48。您可以在 C# 中这样编写:

const int nVertices = 8;
const int vbufCount = 3 * 2 * nVertices;

float[] vertices = new float[vbufCount] {
    -100.0,100.0,-100.0,        //0 position
    -sqrt13,sqrt13,-sqrt13,     //0 normal
    //... 
    -sqrt13,-sqrt13,sqrt13,     //7 normal
    };
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

C# 中 C++ const size_t 的等效项是什么? 的相关文章

随机推荐