zoukankan      html  css  js  c++  java
  • c# Dictionary 遍历,获取key、value

    获取value
    foreach (Student ss in stu.Values)
    {

    MessageBox.Show(ss.Name.ToString());
    }

    ***********************************************

    获取keyforeach (string key in stu.Keys)

    {
    MessageBox.Show(key);
    }
    }
    ****************

    获取key、value
    foreach (KeyValuePair<string, Class1> a in cl)
                {
                    if (a.Key == s1.Name)
                    MessageBox.Show(a.Value.Age.ToString() + "  " + a.Value.Name.ToString ());
                }
    ****************

    连个Dictionary是否相同:

    foreach (var kvp in DictionaryA)
    {    
    int value;    
    if (DictionaryB.TryGetValue(kvp.Key, out value))   
     {       
     if (kvp.Value != value)   
         {        
        hasDictionaryChanged = true;         
       break;    
        }  
      }}
    ****************

    using System.Linq;

    Dictionary<int, string> students;

      var values = from u in students    
               let temp = u.Value.Scores.Sum()  orderby temp
                  select new {
    name = u.Value.Name, totalscore = temp
    };
       ///显示查询结果
    var dicSort = from d in letterWordTotalNum                                  
    orderby d.Key
    select d;

    ***********************************************

    转换为数组:

    Dictionary<uint, object> dic = new Dictionary<uint, object>();

    object[] r = (from val in dic select val.Value).ToArray<object>();

  • 相关阅读:
    用迭代法求x=a−−√。求平方根的迭代公式为 xn+1 = 12(xn + axn) 要求前后两次求出的x的差的绝对值小于10−5
    C 数组
    fofa自动化爬虫脚本更新+详解
    c# winfrom接收http协议body数据
    FLW要求
    modbus工具问题
    2020年总结
    WIFI K型热电偶传感器
    泛海三江烟感JTY-GD-H361 V2.7
    工位终端
  • 原文地址:https://www.cnblogs.com/94cool/p/2151564.html
Copyright © 2011-2022 走看看