maxp
maxp

Reputation: 25181

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

Say I have the code

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

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})

Upvotes: 0

Views: 264

Answers (1)

Yuriy Faktorovich
Yuriy Faktorovich

Reputation: 68747

Use a jagged array

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

Upvotes: 1

Related Questions