Extracting 'single item' from Multi Dimensional Array (c#)
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:
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]);
精彩评论