zoukankan      html  css  js  c++  java
  • 创建Dictionary的几种方法

     1 //Lued
     2 //创建的时候赋值
     3 Dictionary<int, string> dict1 = new Dictionary<int, string>() { { 0, "fuck!" }, { 1, "fuck the world!" } };
     4 Console.WriteLine("dcit1:");
     5 foreach (var dict in dict1) {
     6     Console.WriteLine(dict.Key +"---"+dict.Value);
     7 }
     8 Console.WriteLine();
     9 //用Add方法
    10 Dictionary<int, string> dict2 = new Dictionary<int, string>();
    11 dict2.Add(0, "fuck!");
    12 dict2.Add(1, "fuck the world!");
    13 Console.WriteLine("dcit2:");
    14 foreach (var dict in dict2)
    15 {
    16     Console.WriteLine(dict.Key + "---" + dict.Value);
    17 }
    18 Console.WriteLine();
    19 //用[]下标类似于数组的方法
    20 Dictionary<int, string> dict3 = new Dictionary<int, string>();
    21 dict3[0] = "fuck!";
    22 dict3[1] = "fuck the world!";
    23 Console.WriteLine("dcit3:");
    24 foreach (var dict in dict3)
    25 {
    26     Console.WriteLine(dict.Key + "---" + dict.Value);
    27 }
    28 Console.WriteLine();
    29 Console.WriteLine("ok!");
    30 Console.ReadKey();
  • 相关阅读:
    各种知识点
    链表
    滑动窗口
    数组

    【转】无重复字符的最长子串
    【转】荷兰国旗问题 三指针排序
    【转】回溯思想团灭排列、组合、子集问题
    【LeetCode】45. 跳跃游戏 II
    动态分配内存初始化二维数组
  • 原文地址:https://www.cnblogs.com/awphwb/p/9516548.html
Copyright © 2011-2022 走看看