62,046
社区成员
发帖
与我相关
我的任务
分享
public class TwoValueDictionary<Key, FValue, SValue>
{
private Dictionary<Key, values> innerdic = new Dictionary<Key, values>();
public TwoValueDictionary()
{
}
public void Add(Key key, FValue v1, SValue v2)
{
innerdic.Add(key, new values() { FirstValue = v1, SecondValue = v2 });
}
public class values
{
public FValue FirstValue { get; set; }
public SValue SecondValue { get; set; }
}
public values this[Key key]
{
get {
return innerdic[key];
}
set {
innerdic[key] = value;
}
}
}
//id--------name----------url------
//1---------百度----------www.baidu.com
//2---------谷歌----------www.google.com.hk
//3---------腾讯----------www.qq.com
TwoValueDictionary<int, string, string> dic = new TwoValueDictionary<int, string, string>();
dic.Add(1, "百度", "www.baidu.com");
dic.Add(2, "谷歌", "www.google.com.hk");
dic.Add(3, "腾讯", "www.qq.com");
for (int i = 1; i <= 3; i++)
{
Console.WriteLine(string.Format("previous value is name:{0}, url:{1}", dic[i].FirstValue, dic[i].SecondValue));
dic[i].SecondValue = "www.taobao.com";
dic[i].FirstValue = "淘宝";
Console.WriteLine(string.Format(" now value is name:{0}, url:{1}", dic[i].FirstValue, dic[i].SecondValue));
}
Console.Read();