Monthly Archives: November 2014

Get resource string from .NET application regardless of the current culture


It is common practice that for the multilingual .NET application language specific strings are placed on the Resource of the .NET application. Each supported language has itc own resource file which holds the translated strings. Many year ago I wrote article about it, and you can find it on this location (on Bosnian language).

But what if you want to get the resource string regardless of you current culture. In fact when you call App.Properties.Resources.SomeString you always  the localized string based on the current culture. If you want to get string from other language than current culture, you need to call something else.

For example: Suppose your current culture is English, and you want to get string from the German resources. The picture below shows the resource string in both language specific resources (the first one is German, the second is English resource):

resources
First you need to create Culture info object for german language, and call the GetString method from ResourceManages class by passing the cultureInfor object. The code below show the procedure of getting the string in other that current application language.

System.Globalization.CultureInfo germanInfo = new CultureInfo("de-DE");
string germanWord= Properties.Resources.ResourceManager.GetString("CompatibleMode", germanInfo);

Happy programming

New Features in C# 6.0 – Primary Constructors


Update: This feature is removed from the C# 6.0 specification, probably for the next version of C#.
Primary constructors reduced declaration of various constructors with different arguments. Primary constructors is declare on the type declaration and this is why it so special. For example:

public class Person (string defaultName)
{
 private string m_Name=defaultName;
 public string Name {get;set;}
 public Person()
 {
   Name=defaultName;
 }

}

We can define Primary Constructor in combination on Auto-Property Initializer on the following way:

public class Person (string defaultName)
{
 private string m_Name=defaultName;
 public string Name {get;set;}=defaultName

}

Get every new post delivered to your Inbox.

Join 672 other followers