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 NagarajTOP 100Posted Apr 24, 2016, 8:42 AM EDT
Nice Sharing..
Gowtham RajamanickamTOP 100Posted Apr 10, 2016, 9:55 PM EDT
good one
Priti KumariPosted Jan 6, 2015, 11:49 PM EST
nice
Paweł LulaPosted Jan 6, 2015, 11:11 PM EST
look at last code, it is for Convert.ToInt example
K P Singh ChundawatPosted Jan 6, 2015, 6:49 AM EST
very good ...
Abhijit KakadePosted Jan 5, 2015, 8:29 PM EST
Good one..
Manish Kumar ChoudharyPosted Jan 5, 2015, 6:23 PM EST
Nice..
Harieswaran DPosted Jan 5, 2015, 5:52 PM EST
nice