A Responsive Blogger Website, That Take my blog to the next level.

I am a Software Developer, Learning and experementing with .Net Technology and try to put my Learning altogether here.


We have all sections related to .Net Technology, like .Net-C#, Asp.Net, MVC, jQuery, AngularJs, Sharepoint. Find out more...


Following are the some of the Advantages of using this Web site :-

  • Get Update about latest in .Net world.
  • Collection of Useful, Frequently used .Net Solutions.
  • It’s beautiful on every screen size (try resizing your browser!)
by

2. New Features in C# 6.0 - Support of using static statement for static members


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:

using static System.Console;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            Author a = new Author { Name = "Chandan" };
            WriteLine(a.Name + " has authored " + a.Articles + " articles");
            ReadKey(true);
           
        }
    }


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 :