Reputation: 865
I'm trying to find out program's language and change my string for this language
CultureInfo culture = new CultureInfo("en");
CultureInfo currentCulture = Thread.CurrentThread.CurrentUICulture;
string msg="";
if (currentCulture == culture)
{
msg = "Some words";
}
Even though values of culture and currentCulture are the same if
statement is not working and my msg string is not changing.
Here is my debug results
Name--Value--Type
culture -- {en} -- System.Globalization.CultureInfo
currentCulture -- {en} -- System.Globalization.CultureInfo
Upvotes: 2
Views: 350
Reputation: 98848
Your culture could be represented as en-Us
. Debug your code first. That might be the problem.
CultureInfo
is a class, so it is a reference type. When you compare two different reference with ==
, it always return false
. You can try to compare them based their CultureInfo.Name
property for example. Like;
if(currentCulture.Name == culture.Name)
{
msg = "Some words";
}
Upvotes: 0
Reputation: 273621
CultureInfo
is a reference-type without an override of Equals()
so 2 separate instances will always be unequal.
This little piece of code will print False:
var c1 = new CultureInfo("en");
var c2 = new CultureInfo("en");
Console.WriteLine(c1 == c2);
You can compare on a property, Name
and LCID
seem good candidates.
Upvotes: 1