c#中泛型集合directory和java中map集合对比

c#中directory的基本用法
1、创建及初始化    Dictionary<int, string> myDictionary = new Dictionary<int, string>(); 2、添加元素    myDictionary.Add("C#",0);    myDictionary.Add("C++",1);    myDictionary.Add("C",2);    myDictionary.Add("VB",2); 3、查找元素By Key java中式调用方法keyset放入set集合中,然后利用Iterator迭代器遍历SET   if(myDictionary.ContainsKey("C#"))   {     Console.WriteLine("Key:{0},Value:{1}", "C#", myDictionary["C#"]);   } 4.遍历元素 By KeyValuePair 这是一种关系,和java中的map.entry< , >类似 c# :

 foreach (KeyValuePair<string, int> kvp in myDictionary)   {     Console.WriteLine("Key = {0}, Value = {1}",kvp.Key, kvp.Value);   }

java:

set<map.entry< , >> entrySet=map.entrySet();
Iterator<map,entry< , >> it=entryset.iterator();//利用迭代器便利关系map.entry< , >
while(it.hasnext())
  {
    map.entry< , > me= it.next();//这是一种关系
    me.getkey();
    me.getvalue();
}
5、仅遍历键 By Keys 属性   Dictionary<string, int>.KeyCollection keyCol = myDictionary.Keys;   foreach (string key in keyCol/*string key in myDictionary.Keys*/)   {     Console.WriteLine("Key = {0}", key);   } 6、仅遍历值By Valus属性   Dictionary<string, int>.ValueCollection valueCol = myDictionary.Values;   foreach (int value in valueCol)   {     Console.WriteLine("Value = {0}", value);   }

  

转载于:https://www.cnblogs.com/dandandeyoushangnan/p/4650697.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值