Using Non-Static classes in using block as directive in C# 6

It is a misconception that “using static” keyword is used to including only static classes as directive in C# 6. But I have checked it in Visual Studio 2015 and it can also include Non-static classes.

E.g.

Class1.cs
  1. namespace UsingStatic1  
  2. {  
  3.     public class Class1  
  4.     {  
  5.         public static int Add(int x, int y)  
  6.         {  
  7.             return x + y;  
  8.         }  
  9.     }  

Program.cs
  1. using static UsingStatic1.Class1;  
  2. namespace UsingStatic  
  3. {  
  4.     class Program  
  5.     {  
  6.         static void Main(string[] args)  
  7.         {  
  8.             int i = Add(20, 30);  
  9.         }  
  10.     }  

  UsingStatic1.Class1  is a non-static class and value of i will be 20+30=50;
X

Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now