• C#循环声明一个类


                宗旨就是把实例化的类循环放到字典里面
    Dictionary<string, Data> dic = new Dictionary<string, Data>(); for (int i = 0; i < category.Count(); i++) { dic.Add(category[i].Name, new Data() { data = new string[timeRange.Count - 1] }); }

    给实例化的某个类赋值:

                (dic[category[j].Name]).data[i] = localVar.ToString() == "null" ? "0" : localVar.ToString();

    关于Dictionary的一些应用

            private void GetDicKeyByValue()
            {
                Dictionary<string, string> dic = new Dictionary<string, string>();
                dic.Add("1", "1");
                dic.Add("2", "2");
                dic.Add("3", "2");
                //foreach KeyValuePair traversing
                foreach (KeyValuePair<string, string> kvp in dic)
                {
                    if (kvp.Value.Equals("2"))
                    { 
                        //...... kvp.Key;
                    }
                }
    
                //foreach dic.Keys
                foreach (string key in dic.Keys)
                {
                    if (dic[key].Equals("2"))
                    { 
                        //...... key
                    }
                }
    
                //Linq
                var keys = dic.Where(q => q.Value == "2").Select(q => q.Key);  //get all keys
    
                List<string> keyList = (from q in dic
                                        where q.Value == "2"
                                        select q.Key).ToList<string>(); //get all keys
    
                var firstKey = dic.FirstOrDefault(q => q.Value == "2").Key;  //get first key
            }
  • 相关阅读:
    kvm基本原理
    RAID分类
    监控MySQL主从脚本
    MySQL优化
    查看某个ip地址接在交换机的哪个接口
    rsync+inotify脚本
    docker工作流程
    雅礼集训【Day6-1】字符串
    【模拟试题】困难重重
    Loj #6069. 「2017 山东一轮集训 Day4」塔
  • 原文地址:https://www.cnblogs.com/shinima/p/4258935.html
Copyright © 2020-2023  润新知