Since the new .NET Framework has been announced, several new features have been introduced in C# with its new version. Here, let us learn the concept of using the static classes as a namespace using the using keyword.
Typically, when we have static classes with methods, we call the method using the convention staticClassName.MethodName. But with the new features in C# 6.0, we can directly call the static methods, like they are part of the same classes, instead of using the convention of staticClassName.MethodName. Let's see how to do this.
For our example, let's create a new console application and use the old convention of calling the WriteLine method. So we write the code as,

Now in C# 6.0, we can directly call the Console method. To do this, we first need to add the static class with the following code. In our case, the class is Console. We add it as,
- using static System.Console;
- using static System.Console;
- namespace StaticNamespace
- {
- class Program
- {
- static void Main(string[] args)
- {
- Write("This is Test Value");
- ReadKey();
- }
- }
- }

Now, let's try the same thing using our custom classes. So we add a new static class called MyStaticClass and add a new method that returns a string value as in the following.

We can use the same feature with our classes as well. Run the code and see the results. Happy coding!!

Lalit RaghavPosted Sep 15, 2019, 4:39 AM
Nice sharing
Gajanan ChavhanPosted Feb 26, 2019, 9:14 AM
Thanks for sharing. I don't know if any one else or only me, finding this feature quite confusing as we can not differentiate Instance and statics method visually.
Yashwanth MuthineniPosted Aug 19, 2015, 6:10 AM
Nice Share
Santhakumar MunuswamyPosted Aug 18, 2015, 2:44 PM
Good one
sreenivasa kPosted Aug 17, 2015, 6:24 PM
good
Del WoodcockPosted Aug 17, 2015, 3:07 PM
Nice, C#6 has a lot of great new features. I like using static String a lot.
Arvind UpadhyayPosted Aug 17, 2015, 11:36 AM
Good job...
Pankaj Kumar ChoudharyPosted Aug 17, 2015, 9:55 AM
Nice explain sir. ....
Rahul PrajapatPosted Aug 17, 2015, 9:55 AM
Nice share sir, thanks for sharing
Nihal AhmedPosted Aug 17, 2015, 7:43 AM
good one.
Nilesh JadavPosted Aug 17, 2015, 4:22 AM
Goood one sir :0
Sibeesh VenuPosted Aug 17, 2015, 4:11 AM
Nice Share. Thank you.
Mahesh AllePosted Aug 17, 2015, 3:54 AM
Good One..
Gowtham KPosted Aug 17, 2015, 3:32 AM
Nice thanks for sharing
Manas MohapatraPosted Aug 17, 2015, 2:44 AM
Informative one...
Yashwanth MuthineniPosted Aug 17, 2015, 1:27 AM
Nice share
Ankit BansalPosted Aug 17, 2015, 1:25 AM
thanks for share...
Upendra Pratap ShahiPosted Aug 17, 2015, 12:48 AM
very nice info sir...
Vaikesh K PPosted Aug 17, 2015, 12:34 AM
Nice One
Gopi ChandPosted Aug 16, 2015, 11:34 PM
Good work :)
Manoj KulkarniPosted Aug 16, 2015, 11:23 PM
Nice article. Thank you for sharing
Karthikeyan KPosted Aug 16, 2015, 11:16 PM
Thanks for sharing...
Mohammed IbrahimPosted Aug 16, 2015, 11:13 PM
nice