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>();

  • 相关阅读:
    iisexpress应用讲解
    Flex document文档 下载网址:
    HDU1407 测试你是否和LTC水平一样高
    HDU1715 大菲波数 Java
    HDU1573 大明A+B Java
    HDU1063 Exponentiation Java
    HDU1754 I Hate It 线段树 链式
    HDU2054 A == B? Java
    HDU1166 敌兵布阵 不完全线段树
    HDU1698 Just a Hook 线段树 Lazy思想
  • 原文地址:https://www.cnblogs.com/94cool/p/2151564.html
Copyright © 2011-2022 走看看