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];
                }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM