这样定义列表℃的清单;整型,字符串&GT ;? [英] define a List like List<int,string>?

查看:118
本文介绍了这样定义列表℃的清单;整型,字符串&GT ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个两列的列表,如:

 列表< INT,串> MYLIST =新的List< INT,串>(); 



它说:




使用泛型类型

System.collection.generic.List< T> 要求1类型参数


$ b $。 b
解决方案

您可以使用一成不变结构

 公共结构数据
{
公共数据(INT的intValue,字符串strValue中)
{
IntegerData =的intValue;
StringData是= strValue的;
}

公众诠释IntegerData {搞定;私人集; }
公共字符串StringData是{搞定;私人集; }
}

无功名单=新名单及lt;数据>();

KeyValuePair< INT,串>

 使用Data = System.Collections.Generic.KeyValuePair< INT,串> 
...
无功名单=新名单及lt;数据>();
list.Add(新数据(12345,56789));


I need a two column list like:

List<int,string> mylist= new List<int,string>();

it says

using the generic type System.collection.generic.List<T> requires 1 type arguments.

解决方案

You could use an immutable struct

public struct Data
{
    public Data(int intValue, string strValue)
    {
        IntegerData = intValue;
        StringData = strValue;
    }

    public int IntegerData { get; private set; }
    public string StringData { get; private set; }
}

var list = new List<Data>();

Or a KeyValuePair<int, string>

using Data = System.Collections.Generic.KeyValuePair<int, string>
...
var list = new List<Data>();
list.Add(new Data(12345, "56789"));

这篇关于这样定义列表℃的清单;整型,字符串&GT ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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