当你的才华不能撑起你的野心时,就是你该选择学习的时候了!

C# Dictionary 是否包含key

                Dictionary<string, string> dict = new Dictionary<string, string>();
                list.Add("BENEFICIARY", "受益所有人");
                var res12 = string.Empty;
                var dicKey = "1000";
                dict.TryGetValue(dicKey, out res12);

                res12 = string.Empty;
                dicKey = "BENEFICIARY";
                dict.TryGetValue(dicKey, out res12);

                res12 = string.Empty;
                dicKey = "1000";
                if (dict.Keys.Contains(dicKey))
                {
                    res12 = dict[dicKey];
                }

                res12 = string.Empty;
                dicKey = "BENEFICIARY";
                if (dict.Keys.Contains(dicKey))
                {
                    res12 = dict[dicKey];
                }

                res12 = string.Empty;
                dicKey = "1000";
                if (dict.ContainsKey(dicKey))
                {
                    res12 = dict[dicKey];
                }

                res12 = string.Empty;
                dicKey = "BENEFICIARY";
                if (dict.ContainsKey(dicKey))
                {
                    res12 = dict[dicKey];
                }

 

posted @ 2020-09-17 16:21  hofmann  阅读(3064)  评论(0编辑  收藏  举报