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
- namespace UsingStatic1
- {
- public class Class1
- {
- public static int Add(int x, int y)
- {
- return x + y;
- }
- }
- }
Program.cs- using static UsingStatic1.Class1;
- namespace UsingStatic
- {
- class Program
- {
- static void Main(string[] args)
- {
- int i = Add(20, 30);
- }
- }
- }
UsingStatic1.Class1 is a non-static class and value of i will be 20+30=50;
1059