【发布时间】:2019-09-29 21:29:18
【问题描述】:
.Net 具有非零基数组的特殊内部类型。
C# 语言没有这种类型的语法,所以你不能转换成这种类型。
但二维非零基数组具有普通数组类型。
我想知道为什么只有一维数组有特殊类型?
var array1 = (int[]) Array.CreateInstance( typeof( int ), new[] { 6 }, new[] { -1 } ); // System.InvalidCastException : Unable to cast object of type 'System.Int32[*]' to type 'System.Int32[]'
var array2 = (int[,]) Array.CreateInstance( typeof( int ), new[] { 6, 6 }, new[] { -1, -1 } ); // it works
【问题讨论】:
-
你不能转换成这种类型你可以。有一些技巧。
标签: c# arrays .net .net-core clr