有关C#语言环境的问题 [英] A question about locale in c#

查看:58
本文介绍了有关C#语言环境的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

再见,

我有一个桌面应用程序.此应用程序全部与计算数字有关.但是最近,我发现了一个问题.在希腊,它们的数字格式与加拿大不同.例如,在加拿大,我们使用1,000,000.00,但在希腊,他们使用1.000.000,00.如果我的应用程序从希腊读取了一个文件,则显示格式无效,无法读取".我设置了

Hi all again,

I have a desktop application. This application is all about computing numbers. But recently, I found a problem. In Greece, they have different number format from canada. For example, in canada, we use 1,000,000.00, but in Greece, they use 1.000.000,00. If my application read a file from Greece, it said "invalid formatting and cannot be read". I set

thread.CurrentThread.CurrentCulture = new CultureInfo("el-GR");


在我的应用程序中,它肯定无法正常工作.如何通过编程解决此问题?我完全不知道.
在此先感谢.


in my application, it does not work for sure. How can I solve this problem from programming? I totally have no clue.
Thanks in advance.

推荐答案

如果可能,数字应采用跨文化使用的格式存储.这可以通过以下方式完成:将它们存储在二进制文件中,从而使区域性无关紧要,或者通过使用单个已知区域性(最好是不变区域性)将它们存储为文本字符串.这样,您就始终知道如何从文件中读取数字,并可以使用要在应用程序中显示这些数字的任何其他区域性.

Decimal.ToString(IFormatProvider)的文档 [ BinaryReader类的文档 [ BinaryWriter类的文档 [
If possible, numbers should be stored in a format that works across cultures. This can be done by storing them in binary so culture is irrelevant, or by storing them as text strings using a single known culture (preferably the Invariant culture). This way you always know how to read in the numbers from your file(s) and can use any other culture you want to display those numbers in your application.

Documentation for Decimal.ToString(IFormatProvider)[^] - Used to write a decimal value using a specific culture. Other numeric types and String.Format() have similar overloads using IFormatProvider.

Documentation for BinaryReader class[^] - Used to read in data from binary files.

Documentation for BinaryWriter class[^] - Used to write data to binary files.


这篇关于有关C#语言环境的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆