using static - CSharp Custom Type

CSharp examples for Custom Type:namespace

Introduction

You can import not just a namespace, but a specific type, with the using static directive.

All static members of that type can then be used without being qualified with the type name.

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

using static System.Console;

class Test
{
  static void Main() { WriteLine ("Hello"); }
}

if we import the following enum type:

using static System.Windows.Visibility;

we can specify Hidden instead of Visibility.Hidden:

var textBox = new TextBox { Visibility = Hidden };

Related Tutorials