开发者

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

开发者 https://www.devze.com 2023-03-09 20:27 出处:网络
Say I have the code var marray = new int[,]{{0,1},{2,3},{4,5}}; 开发者_StackOverflowIs it possible to get a reference to the first item- i.e. something that looked like:

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

精彩评论

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