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, 12:39 AM EDT
Nice sharing
Gajanan ChavhanPosted Feb 26, 2019, 4:14 AM EST
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, 2:10 AM EDT
Nice Share
Santhakumar MunuswamyPosted Aug 18, 2015, 10:44 AM EDT
Good one
sreenivasa kPosted Aug 17, 2015, 2:24 PM EDT
good
Del WoodcockPosted Aug 17, 2015, 11:07 AM EDT
Nice, C#6 has a lot of great new features. I like using static String a lot.
Arvind UpadhyayPosted Aug 17, 2015, 7:36 AM EDT
Good job...
Pankaj Kumar ChoudharyTOP 100Posted Aug 17, 2015, 5:55 AM EDT
Nice explain sir. ....
Rahul PrajapatPosted Aug 17, 2015, 5:55 AM EDT
Nice share sir, thanks for sharing
Nihal AhmedPosted Aug 17, 2015, 3:43 AM EDT
good one.
Nilesh JadavPosted Aug 17, 2015, 12:22 AM EDT
Goood one sir :0
Sibeesh VenuTOP 100Posted Aug 17, 2015, 12:11 AM EDT
Nice Share. Thank you.
Mahesh AllePosted Aug 16, 2015, 11:54 PM EDT
Good One..
Gowtham KTOP 100Posted Aug 16, 2015, 11:32 PM EDT
Nice thanks for sharing
Manas MohapatraPosted Aug 16, 2015, 10:44 PM EDT
Informative one...
Yashwanth MuthineniPosted Aug 16, 2015, 9:27 PM EDT
Nice share
Ankit BansalPosted Aug 16, 2015, 9:25 PM EDT
thanks for share...
Upendra Pratap ShahiPosted Aug 16, 2015, 8:48 PM EDT
very nice info sir...
Vaikesh K PPosted Aug 16, 2015, 8:34 PM EDT
Nice One
Gopi ChandPosted Aug 16, 2015, 7:34 PM EDT
Good work :)
Manoj KulkarniPosted Aug 16, 2015, 7:23 PM EDT
Nice article. Thank you for sharing
Karthikeyan KPosted Aug 16, 2015, 7:16 PM EDT
Thanks for sharing...
Mohammed IbrahimPosted Aug 16, 2015, 7:13 PM EDT
nice