本文主要是介绍C# TryGetValue用法,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
TryGetValue() 作为获取value的方法并且做判断条件 取到了返回true并且赋值给 workStudyCourseTypeName 否则返回false
需求:如果是属于dictionary那几种情况 则输出 Hello + Value
//TryGetValue() 作为获取value的方法并且做判断 取到了返回true并且赋值给 workStudyCourseTypeName 否则返回false
//需求:如果是属于dictionary那几种情况 则输出 Hello + Value
string content = "{Transcript.Statement}";
if (string.IsNullOrWhiteSpace(content) || content.Contains("{Transcript.Statement}"))
{var workStudyCourseType = new Dictionary<string, string>{{ "WSDC","Work-Study Post-Diploma" },{ "WSP2SD","Work-Study Post-Diploma" },{ "WSPAD","Work-Study Post-Diploma" },{ "WSC2PTD","Work-Study Certificate" },{ "WSPSD","Work-Study Post-Diploma" },{ "WSC","Work-Study Certificate" },};if (workStudyCourseType.TryGetValue("WSDC", out var workStudyCourseTypeName)){Console.WriteLine($"Hello {workStudyCourseTypeName}");}
}
仅供学习参考,如有侵权联系我删除
这篇关于C# TryGetValue用法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!