Like me, do you also get tired of using the static class name each time while calling a method of the static class? For example, if you want to use the WriteLine of the static class Console, each time you need to use Console.WriteLine(“”). Again, this is not the biggest problem but still it annoys. C# 6.0 solves this problem by allowing us to make static members of a type available without the type prefix via new static directives. So we can simplify the use of the static class methods as shown in the listing below:
In the above snippet, we are including the System.Console class by using the static statement and then using methods like WriteLine, ReadKey etc. without having each time to add the class name of Console. This makes the code much cleaner.
0 comments :
Post a Comment