C# 6.0 Features Series
- How to try C# 6.0 and Rosyln?
- Getter-only (Read Only) Auto Properties in C# 6.0
- Lambda and Getter Only Auto-Properties in C# 6.0
- Initializers for Read-Only Auto Properties in C# 6.0
- Initializers via Expression Auto Properties in C# 6.0
- C# 6.0 – A field initializer cannot reference the non-static field, method, or property
- Lambda Expression for Function Members in C# 6.0
- Dictionary Initializers (Index Initializers) in C# 6.0
- Expression Bodies on Methods returning void in C# 6.0
- using keyword for static class in C# 6.0
- Unused namespaces in Different Color in Visual Studio 2015
- Null-Conditional Operator in C# 6.0
- Null-Conditional Operator and Delegates
- nameof Operator in C# 6.0
- Contextual Keywords in C#
- String Interpolation in C# 6.0
- Exception Filters in C# 6.0
- Await in Catch and finally block in C# 6.0
In the earlier versions of C# , using keyword was used primarily for the namespaces to be included in the C# page. There were other usages of using keyword like using block , namespace alias etc.
The C# 6.0 lets the developers use the using directive for the static class similar to the one the developers use for namespace.
using keyword for static class in C# 6.0
This feature lets the developers to invoke the static methods of the class without specifying the class name.
Assume that you have a class called Console which has a static method called WriteLine . In C# 5.0 and earlier version , you would end up specifying Console.WriteLine(“developerpublish.com C# tutorials”); as show below.
using System; using System.Collections.Generic; using System.Linq; namespace MobileOSGeekApp { class Program { static void Main(string[] args) { Console.WriteLine("developerpublish.com C# tutorials"); Console.ReadLine(); } } }
In C# 6.0 , you can simply include the class name with the using class Eg : using System.Console; and when using the method , invoke it without the class name as shown below.
using System; using System.Collections.Generic; using System.Linq; using System.Console; namespace MobileOSGeekApp { class Program { static void Main(string[] args) { WriteLine("developerpublish.com C# tutorials"); ReadLine(); } } }