什么是T [,]和T [*,*]之间的区别? [英] What is the difference between T[,] and T[*,*]?

查看:197
本文介绍了什么是T [,]和T [*,*]之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的谷歌柔术失败我。问题是在标题......是什么区别 T [,] T [*,*]
我要寻找一个2,2-1 / 2的部分答案是:

My Google-Jitsu is failing me. Question is in the title... What is the difference between T[,] and T[*,*]? I am looking for a 2, 2-1/2 part answer:


  1. 外行的(或超建筑师)纯英文的解释与例如code。

  1. Layman's (or super architect's) plain english explaination with example code.

链接到这种区别的正式文件。

Link to the formal documentation of this distinction.

奖励:指向在定义这个C#4款规格和页码。 (这不是在教派12阵列)

Bonus: Point to subsection and page number in the C# 4 spec that defines this. (It is not in sect 12 "Arrays")

我得到了这个概念<一href=\"http://social.msdn.microsoft.com/Forums/en/csharplanguage/thread/e6f84f77-1a09-4dd9-a2af-eb3a54e9c7bc\">here.

推荐答案

T [] 表示T的从零开始的数组的(数组[0]它的第一个元素)

T[] means a zero-based array of T (array[0] is its first element)

T [*] 表示一个非从零开始的T阵列的(数组[0]是不是它的第一要素,甚至可以出界)

T[*] means a non-zero-based array of T (array[0] is not its first element and can even be out of bounds)

的<一个href=\"http://social.msdn.microsoft.com/Forums/en/csharplanguage/thread/e6f84f77-1a09-4dd9-a2af-eb3a54e9c7bc\"相对=nofollow>从你的问题链接解释说,没有类型 T的数组[*,*] ,因为所有的多维数​​组 T [,] 被视为未知的约束下阵列。

The link from your question explains that there is no array of type T[*,*], because all multi-dimensional arrays of T[,] are treated as arrays with unknown lower-bound.

code片段展示了如何创建的一个实例T [*] 。请注意,你不能将它转换为 T [] ,因为它们是不同的类型。 A [0] 这里将抛出OutOfRangeException,第一个元素的数组索引为1的(啊,好老帕斯卡天......)

Code snippet below shows how you can create an instance of T[*]. Note that you can not cast it to T[], because they are different types. a[0] here will throw an OutOfRangeException, the index of the first element in this array is 1 (ah, good old Pascal days...).

Array a = Array.CreateInstance(typeof(String), new Int32[] { 1 }, new Int32[] { 1 });
Console.WriteLine(a.GetType());    // System.String[*]  

更多例如code

奖金 C#语言规范说的阵列范围从0到长度元素的指数 - 1的。显然,语言不为非零基于阵列提供内置支持,它只是一个自定义的数据结构,您可以创建;虽然具体的编译器恰巧有其类型的特殊符号和VS使用标准的可视化阵列为他们当你正在调试的感觉。

Bonus. The C# language spec says, "The indices of the elements of an array range from 0 to Length - 1". Obviously, the language does not provide built-in support for non-zero-based arrays, it's just a custom data structure that you can create; although specific in a sense that the compiler happens to have a special symbol for its type and VS uses standard array visualizer for them when you're debugging.

另请参阅:

<一个href=\"http://stackoverflow.com/questions/5728409/how-to-create-a-1-dimensional-array-in-c-sharp-with-index-starting-at-1\">How建立在C#中使用索引的一维数组中,以1

C#:非零基于阵列是不符合CLS

这篇关于什么是T [,]和T [*,*]之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆