开发者

Extracting 'single item' from Multi Dimensional Array (c#)

Say I have the code

var marray = new int[,]{{0,1},{2,3},{4,5}};
开发者_StackOverflow

Is it possible to get a reference to the first item - i.e. something that looked like:

var _marray = marray[0];
//would look like: var _marray = new int[,]{{0,1}};

Instead, when referencing marray from a one dimensional context, it sees marray as having length of 6

(i.e. new int[]{0,1,2,3,4,5})


Use a jagged array

var marray = new[] { new[] { 0, 1 }, new[] { 2, 3 }, new[] { 4, 5 } };
Console.WriteLine(marray[0][1]);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜