Javatpoint Logo
Javatpoint Logo

C# Using Static Directive (Static Import)

C# using static directive helps us to access static members (methods and fields) of the class without using the class name. If we don?t use static directive, we need to use class name to call static members each time.

It allows us to import static members of a class into the source file. It follows a syntax that is given below.

C# using static directive syntax

In the following example, we are not using static directive. We can see that, to access static method of Math class, class name is used.

C# Example without using static directive

Output

12
javatpoint.com

In the following example, we are using static directive in the source file. So, it does not require class name before calling the method.

C# Example with using static directive

We can see, it produces the same result even after removing the type from the function call.

Output

12
javatpoint.com





Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


B.Tech / MCA