Content
As we all know Microsoft has launched a new version of C# called C# 6.0 with Visual Studio Ultimate 2015 Preview and there is new feature in C# 6.0 that is based on "Static Classes".
This feature allows us to access the static methods without using Class name each and every time. Let's see this feature.
I am using Visual Studio Ultimate 2015 Preview.
Open Visual Studio 2015 and select "File" -> "New" -> "Project..." and fill in the project name as "Console Application1".
After creating the project, I will access some common static methods in "program.cs" without the help of class name every time.
Basically we used to access the static methods using class name like:
- Console
- Convert
- Math
Console: Generally we use to access the methods of the "Console" Class until C# 5.0.
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Hi");
- }
- }
But in C# 6.0, we can access the methods of the "Console" Class or static class directly. For this we need to access the "Console" class using "using" like namespaces.
- using System.Console;
- class Program
- {
- static void Main(string[] args)
- {
- WriteLine("Hi");
- }
- }
Convert: Similarly we previously accessed the methods of the "Convert" Class until C# 5.0.
- class Program
- {
- static void Main(string[] args)
- {
- int i = Convert.ToInt32(8.0);
- }
- }
But in C# 6.0, we can access the methods of the "Convert" class or static class directly. For this we need to access the "Convert" class using a "using" like namespaces.
- using System.Convert;
- class Program
- {
- static void Main(string[] args)
- {
- int i = ToInt32(8.0);
- }
- }

Math: Similarly we previously accessed the methods of the "Math" Class until C# 5.0.
- class Program
- {
- static void Main(string[] args)
- {
- Double i = Math.Sqrt(8.0);
- }
- }
But in C# 6.0, we can access the methods of the "Math" class or static class directly. For this we need to access the "Math" class using "using" like namespaces.
- using System.Math;
- class Program
- {
- static void Main(string[] args)
- {
- Double i = Sqrt(8.0);
- }
- }

Conclusion: Now you understand the new feature of C# 6.0 that allows the use of the "Static Methods" in an easy way.

Kuppurasu NagarajPosted Apr 24, 2016, 12:42 PM
Nice Sharing..
Gowtham RajamanickamPosted Apr 11, 2016, 1:55 AM
good one
Priti KumariPosted Jan 7, 2015, 4:49 AM
nice
Paweł LulaPosted Jan 7, 2015, 4:11 AM
look at last code, it is for Convert.ToInt example
K P Singh ChundawatPosted Jan 6, 2015, 11:49 AM
very good ...
Abhijit KakadePosted Jan 6, 2015, 1:29 AM
Good one..
Manish Kumar ChoudharyPosted Jan 5, 2015, 11:23 PM
Nice..
Harieswaran DPosted Jan 5, 2015, 10:52 PM
nice