2D阵列的对象列表 [英] List of object to 2D Array
本文介绍了2D阵列的对象列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何创建2d字符串MyList数组?
谢谢
How create a 2d string Array of MyList ?
Thanks
public class Result
{
public string Name;
public string Port;
public string DeviceID;
}
List<Result> MyList = new List<Result>();
推荐答案
如果是你的意思是你想从现有的List< Result>
创建一个string [] []
,然后Linq方法使它变得非常简单:
If what you mean is that you want to create astring[][]
from an existingList<Result>
that has values, then Linq methods make it pretty simple:
List<Result> MyList = new List<Result>();
MyList.Add(new Result { Name = "name1", Port = "Port1", DeviceID = "DeviceID1" });
MyList.Add(new Result { Name = "name2", Port = "Port2", DeviceID = "DeviceID2" });
MyList.Add(new Result { Name = "name3", Port = "Port3", DeviceID = "DeviceID3" });
string[][] data = MyList.Select(m => new string[] { m.Name, m.Port, m.DeviceID }).ToArray();
如果您的意思是其他,那么您需要更详细地解释。
If you mean something else, then you need to explain in better detail.
这篇关于2D阵列的对象列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文