C# Dictionary和SortedDictionary的简介

2020-01-05 09:43:00于海丽

  ContainsKey:      确定 Dictionary是否包含指定的键。

  ContainsValue:   确定 Dictionary是否包含特定值。             

  GetEnumerator:  返回循环访问 Dictionary的枚举数。

  GetType:             获取当前实例的 Type。 (从 Object 继承。)

  Remove:             从 Dictionary中移除所指定的键的值。

  ToString:             返回表示当前 Object的 String。 (从 Object 继承。)

  TryGetValue:      获取与指定的键相关联的值。

使用for循环遍历键值


Dictionary<string, int> Dict = new Dictionary<string, int>();
      Dict .Add( "a", 1 );
      Dict .Add( "b", 2 );
      Dict .Add( "c", 3 );
      Dict .Add( "d", 4 );
      Dict .Add( "e", 5 );
      Dict .Add( "f", 6 );
      for(int i = 0 ; i < DicTest.Count ; i++)
      {
        Debug.Log(DicTest.ToList()[i].Key + ":" + DicTest.ToList()[i].Value);
      } 

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对ASPKU的支持。