Changes To Base Class Library With .NET Framework 4.6

Overview

Microsoft released the new version of .Net Framework, .NET Framework 4.6, with Visual Studio 2015 Preview on November 12, 2014. It was announced at the day of Visual Studio Connect() event from New York, USA. In this article we will learn about some small changes to the .NET Base Class Libraries (BCL). So before becoming familiar with the changes in the Base Class Libraries we should be familiar with it.

Base Class Libraries

The .NET Framework Base Class Libraries is a library of classes, interfaces and value types that provide access to system functionality. We can say that it is the foundation of the .NET Framework on which the applications, controls and components of the .NET Framework are built. In .NET Framework 4.6 many new APIs have been added to enable the following key scenarios.

  • Some CultureInfo properties are read-write rather than read-only. 

Some CultureInfo properties are read-write rather than read-only

The CultureInfo.CurrentCulture and CultureInof.CurrentUICulture properties are now read-write rather than read-only. In previous versions of the .NET Framework these are read-only properties so we couldn't create any specific culture but now it has become possible to create a specific culture. So before trying to understand the changes of these two properties we should be familiar with the basics of these properties.

The System.Globalization is the namespace that contains the definition for the CultureInfo class that defines culture related information like languages, country/region, calendars, currency and numbers. All the classes that come under the System.Globalization namespace are useful for developeing globalized applications. The CultureInfo class has very many properties, some of them are listed below:

  • CurrentCulture
  • CurrentUICulture
  • CultureTypes
  • CurrentCulture
  • Calendar
  • DateTimeFormat
  • EnglishName
  • InvariantCulture
  • StringInfo
  • TextInfo
  • and more... 

Notes

There are many properties available for the CultureInfo class but in this article we will only explore those of which some changes were made by Microsoft. So the following are the two properties in which changes were made, CurrentCulture and CurrentUICulture.

CurrentCulture

The CurentCulture property is used to get or set the current culture used by the current thread. In other words in .NET Framework 4.6, it became a read-write property. It was a read-only property before the release of .NET Framework 4.6 and v4.5.2. It is responsible for formatting and parsing the values of the current thread.

Example I (with .NET Framework 4.6 in Visual Studio 2015 Preview): 

  1. namespace TestConsoleApplication  
  2. {  
  3.     class ProgramInNETFramework4pont6   
  4.     {  
  5.         static void Main(string[] args)  
  6.         {           
  7.   
  8.             //Using as read-only property  
  9.             Console.WriteLine("Current Culture: "+CultureInfo.CurrentCulture);  
  10.             Console.WriteLine("Current Name (in English)"+CultureInfo.CurrentCulture.EnglishName);  
  11.             Console.WriteLine(string.Format(CultureInfo.CurrentCulture,"Amount: {0:C2}",25000));  
  12.             Console.WriteLine("Today is : " + CultureInfo.CurrentCulture.Calendar.GetDayOfWeek(DateTime.Now));  
  13.   
  14.   
  15.             //Usin  as read-write property  
  16.             CultureInfo.CurrentCulture = CultureInfo.CreateSpecificCulture("en-IN");  
  17.             Console.WriteLine("Current Culture: " + CultureInfo.CurrentCulture);  
  18.   
  19.   
  20.             CultureInfo.CurrentCulture.EnglishName = CultureInfo.CreateSpecificCulture("English <India>");  
  21.             Console.WriteLine("Culture Name (in English) " + CultureInfo.CurrentCulture);  
  22.   
  23.             CultureInfo.CurrentCulture.EnglishName = CultureInfo.CreateSpecificCulture("English <India>");  
  24.             Console.WriteLine("Culture Name (in English) " + CultureInfo.CurrentCulture);  
  25.                
  26.   
  27.             
  28.         }  
  29.     }  
  30.       
  31. }  

Note:

The preceding program written in .NET Framework 4.6 is well, there is no issue of the read-only property but when I write the same program in v4.5 and v4.0 both will produce some syntax error like: "Can not be assigned to read-only property". 

I would like to share that this feature is not working properly with each Visual Studio 2015 Preview  but it has been announced by the Microsoft. If this code is not working in your system, there is nothing to worry about because this preview version is released for testing purposes. It will however work with the final release. See

Let's see it practically!

Example II (with .NET Framework 4.5 in Visual Studio 2013):

Now we will write the same program in .NET Framework 4.5, it will produce an error!  

Framework45
Note:

It's saying "It's a read-only property",
System.Globalization.CultureInfo.CurrentCulture can not be assigned.
System.Globalization.CultureInfo.EnglishName can not be assigned.

Example III (with .NET Framework 4.0 in Visual Studio 2010):

Again we will write the same program in .NET Framework 4.0, it will also produce an error!

Framework4

Note:

It's saying "It's a read-only property",
System.Globalization.CultureInfo.CurrentCulture can not be assigned.
System.Globalization.CultureInfo.EnglishName can not be assigned.

CurrentUICulture

CurrentUICulture represents the current culture of the application used by resource files (.resx files). It was a read-only property before the release of .NET Framework 4.6 and  v4.5.2. Now it became a read-write property with .NET Framework 4.6. It is responsible for formatting and parsing the values of the current thread. Let's see it with some example programs.

Example I (with .NET Framework 4.6 in Visual Studio 2015 Preview):

[ PROGRAM ]

*OutputImage

Example II (with .NET Framework 4.5 in Visual Studio 2013):

/UIFrame45

Example III (with .NET Framework 4.0 in Visual Studio 2010):

UIFramewok4

Summary

In this article we learned about the changes to the Base Class Libraries specially in the CurrentUICulture and CurrentCulture properies of the CultureInfo class in the namespace System.Globalization. Thanks! 

Up Next
    Ebook Download
    View all
    Learn
    View all