简体   繁体   English

从多维数组中提取“单个项目”(c#)

[英]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 - ie 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相反,当从一维上下文中引用marray时,它会将marray视为长度为 6

(ie new int[]{0,1,2,3,4,5} ) (即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]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM