gpt4 book ai didi

c# - 有没有办法将 "try parse"字符串发送到 System.Globalization.CultureInfo

转载 作者:太空狗 更新时间:2023-10-30 01:23:02 24 4
gpt4 key购买 nike

在 C# 中,我正在使用

CultureInfo.GetCultureInfo(myCulture)

但字符串变量的格式可能不正确,有没有办法先尝试解析字符串或先验证它。

最佳答案

以下生成所有文化的集合:

CultureInfo.GetCultures(CultureTypes.AllCultures)

从那里,您可以执行以下操作,而不是 GetCultureInfo:

.FirstOrDefault(c => c.Name == myCulture)

而不是 AllCultures 您可能想要过滤掉 SpecificCultures .

关于c# - 有没有办法将 "try parse"字符串发送到 System.Globalization.CultureInfo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12345614/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com