Default culture

I am using .NET4

I am using en-US locale and want my application to work this way.

Some of my software clients, however, are from countries (such as Norway) where the decimal point is represented as ",".

Therefore, the following line throws an exception for my Norwegian client:

double a = double.Parse("1.5");

I read that I can change CurrentCulture as follows:

Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

The problem is that I have to do this for each thread separately. Moreover, I'm not quite sure where I will implicitly parse the double, so I will have to do this every time I create Thread ...

I read that there is a solution for .NET 4.5 by changing the setting DefaultThreadCurrentCulture.

Does anyone think of a general solution for this without updating my version of the .NET Framework?

+4
2

, , , , - CultureInfo.InvariantCulture:

double a = double.Parse("1.5", CultureInfo.InvariantCulture);

, , , , .

:

?

+4

, , .Net. , , , , , case.here: -

void AskForACountry() { frmEdit = new Form(); frmEdit.ShowIcon = false; cmbxLang = new ComboBox(); frmEdit.Size = new Size(199, 113); Button btnSetLang = new Button(); btnSetLang.Size = new Size(88, 23); btnSetLang.Text = "Set Language"; btnSetLang.Location = new Point(40, 39); cmbxLang.Location = new Point(28, 12); cmbxLang.DropDownStyle = ComboBoxStyle.DropDownList; String[] arrayCountry = { "Catalan - Spain", "Chinese - China", "Chinese - Hong Kong", "Chinese - Taiwan", "Danish - Denmark", "Dutch - Netherlands", "English - Australia", "English - Canada", "English - Great Britain", "English - US", "Finnish - Finland", "French - Canada", "French - France", "German - Germany", "Italian - Italy", "Japanese - Japan", "Korean - Korea", "Norwegian - Norway", "Polish - Poland", "Portuguese - Brazil", "Portuguese - Portugal", "Russian - Russia", "Spanish - Mexico", "Spanish - Spain", "Swedish - Sweden" }; cmbxLang.DataSource = arrayCountry.ToList(); btnSetLang.Click += new EventHandler(btnSetLang_Click); frmEdit.Controls.Add(cmbxLang); frmEdit.Controls.Add(btnSetLang); MessageBox.Show("Please select a country that fits your computer default language and dialect.", "Select A Country"); frmEdit.StartPosition = FormStartPosition.CenterScreen; frmEdit.AcceptButton = btnSetLang; frmEdit.ShowDialog(); }

-3

All Articles