扩展类

liyoubaidu 2010-08-11 05:41:30
类:
    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();
...全文
100 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
asdfa23rdadsdfa 2010-08-11
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 wwfgu00ing 的回复:]
what are you doing ?
[/Quote]

up
一克代码 2010-08-11
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 wwfgu00ing 的回复:]
what are you doing ?
[/Quote]

up
wwfgu00ing 2010-08-11
  • 打赏
  • 举报
回复
what are you doing ?
sxmonsy 2010-08-11
  • 打赏
  • 举报
回复
每天回帖即可获得10分可用分!
Peter200694013 2010-08-11
  • 打赏
  • 举报
回复
什么问题?

分享?
dqsweet 2010-08-11
  • 打赏
  • 举报
回复
没有问题?
symbol_bc 2010-08-11
  • 打赏
  • 举报
回复
楼主想干嘛??

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧