访问“测量系统” C# 中的单位名称(kg/lb、m/in 等)
Windows 允许将测量系统
配置为公制
或US
有没有办法使用此设置来读取C# 中的(缩写)单位名称?
例如,当以公制
显示重量时,我想显示kg
,但在US
中我想显示lb
。对于长度、体积等也是如此。
我查看了 SystemInformation、CultureInfo、Configuration 和 Globalization,但没有看到任何明显的东西。我错过了什么或者我找错地方了吗?
Windows allows configuration of Measurement system
to Metric
or U.S.
Is there a way to use this setting to read (abbreviated) unit names in C#?
e.g. when displaying a weight in Metric
I want to show kg
but in U.S.
I want to show lb
. Similarly for length, volume, etc.
I've looked at SystemInformation, CultureInfo, Configuration, and Globalization, but didn't see anything obvious. Did I miss something or am I looking in the wrong place?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信你能做的最好的事情就是确定你的文化是否是公制的,然后自己处理。我不认为有任何内置格式?我可能是错的,但我在任何地方都找不到任何参考。
这将使您能够确定您的文化是否是公制的:
I believe the best you can do is to determine if your culture is metric or not and then handle it yourself. I don't think there's any built in formatting? I may be wrong though, but I cannot find any reference to it anywhere.
This will allow you to determine if your culture is metric or not:
@GenericTypeTea 关于 RegionInfo 是查看位置的说法是正确的。
此外,F# 还包含许多用于处理测量单位的功能。在 F# 中构建一些您需要的内容并从 C# 调用它可能是有意义的。
请参阅 此博文以及后续博文,了解有关 F# 和测量单位的信息。
@GenericTypeTea is right about the
RegionInfo
being the place to look.Additionally F# contains a lot of features for working with units of measure. It might make sense to build some of what you need in F# and call it from C#.
See this blog post and the subsequent posts for information about F# and units of measure.