With C# 6.0, “using” directive is supported with Static keyword. The advantage of static keyword with using directive is that static methods would now be available in global scope i.e. static methods can be used without a type prefix of any kind.
Example:
System.Console is a static class and most of the methods from this class such as WriteLine, ReadKey are used with its type as in the following:
Using System.Console;
Console.WritLine(“Hi”);
Console.ReadKey();
Using static System.Console;
WritLine(“Hi”);
ReadKey();
This eliminates the need to qualify the static member with its type.
Pitfalls of using static
- Users must be very careful with the using static directive. They should take care of the fact that clarity of the code isn’t compromised.
namespace myNameSpaceA
namespace myNameSpaceB- internal static class A
- {
- public bool CheckElement(int i)
- {
- return true;
- }
- }
In main function:- Internal static Class B
- {
- Public bool CheckElementAt(int i)
- {
- Return true;
- }
- }
Using static myNameSpaceA
It may be misleading looking at the CheckElement which Class it belongs to. However, more explicitly, the call is from A. when, in fact, B. CheckElement is what’s needed here.- TestMethod(int elementFromB)
- {
- if(CheckElement()){ //;};
- }
Although the code is certainly readable, it’s incorrect and, at least in this case, it is advised avoiding the using static syntax is probably better.
Well, another point to be noted is that if using static directives are written for both Class A and Class B, it would cause compilation errors while calling CheckElement.
- Extension Method:
With C# 6.0, Extension methods aren’t moved into global scope as described above. First, extension methods are intended to be treated as instance methods on an object and it’s not a normal pattern to call them as static methods directly off the type.
So enjoy using “static” with “using” but be careful and clear with your intentions.

Pankaj Kumar ChoudharyPosted Sep 2, 2015, 8:45 PM
Nice Explain Sir........
Santhakumar MunuswamyPosted Sep 2, 2015, 2:45 PM
Thanks for sharing
Mohammed IbrahimPosted Sep 2, 2015, 11:25 AM
thanks for sharing information
RakeshPosted Sep 2, 2015, 10:59 AM
Good one
Rajeesh MenothPosted Sep 2, 2015, 7:21 AM
Nice Share
Karthikeyan KPosted Sep 2, 2015, 7:18 AM
Good one sir..Thanks for sharing