读书人

asp.net c#非常简单的有关问题解决马

发布时间: 2013-03-13 10:56:58 作者: rapoo

asp.net c#非常简单的问题,解决马上给分
Dictionary<string, string>是键和值的集合,那有没有非集合的写法?
我不需要集合,但需要像Dictionary一样能够设置key和value

例如:


public object<string, string> demo(){
return null;
}

以上代码是错误的,没有这种写法
[解决办法]
KeyValuePair<int, string> pair = new KeyValuePair<int, string>();
[解决办法]
自己定义一个
 public class myObject<TKey, TValue>
{
public TKey Key { get; set; }
public TValue Value { get; set; }
}

public myObject<string, string> demo(){
return null;
}

读书人网 >C#

热点推荐