CSharp - Namespace using static


You can import a specific type by using static directive.

All static members of that type can be used without using its type name.

using static directive imports all accessible static members of the type, including fields, properties, and nested types.

You can static using enum types.

WriteLine() method is a static method from Console class.

In the following example, we call the Console class's static WriteLine method:


using System;
using static System.Console;
class MainClass//from   www  .  ja va 2s  .  co m
   public static void Main(string[] args)

       System.Console.WriteLine("Hello");//System.Console. is redundant
       Console.WriteLine("Hello");       //Console. is redundant
       WriteLine ("Hello"); //No namespace and No type name