列表中的多列c# [英] multiple column in list c#

查看:55
本文介绍了列表中的多列c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是这个可能的列表< int,string>?

解决方案

我们不知道你想如何使用这样的集合:用于按键访问(然后看看解决方案1),或作为列表。如果是列表,则创建结构或类,例如:



  struct  ListElement {
public int ID,
public string 名称,
}

// ...

List< ListElement> list = new 列表< ListElement>();









另一种选择是使用元组http://msdn.microsoft.com/en-us/library/system.tuple.aspx [ ^ ]。



- SA


如果你想要一个由带有字符串值的整数键组成的List,那么你可以使用 Dictionary< int,string>

is this possible list<int,string>?

解决方案

We don't know how you want to use such collection: for access by key (then see Solution 1), or as list. If as list, create a structure or a class, for example:

struct ListElement {
   public int Id,
   public string Name,
}

// ...

List<ListElement> list = new List<ListElement>();



[EDIT]

Another option is using the tuple: http://msdn.microsoft.com/en-us/library/system.tuple.aspx[^].

—SA


If you want a List consisting of an integer key with a string value, then you would use Dictionary<int,string>.


这篇关于列表中的多列c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆