CSharp - Namespace using static

Introduction

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:

Demo

using System;
using static System.Console;
class MainClass//from w  w w. j a va  2 s . com
{
   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

   }
}

Result