Saturday, January 24, 2015

Recent updates to C# 6.0 syntax with new version of Visual Studio 2015 CTP

This blog post is part of C# 6.0 Features Series.
Recently, Microsoft has announced new version of Visual Studio 2015 and I have downloaded it. At the same time I was checking what’s new in Visual Studio 2015 CTP newer version and and I have found that suddenly my c# 6.0 new features solutions  stopped working.

The first problem it got is with static class using features. Following was my code.
using System.Console;

namespace StaticClassUsing
{
    class Program
    {
        static void Main(string[] args)
        {
            WriteLine("With using statement");
        }
    }
}

Now when you run this it was giving error like following.

Error

So created a stack overflow question at following

http://stackoverflow.com/questions/28123349/using-statement-with-static-class-is-not-working-in-visual-studio-2015-ctp

Thanks to answer from user HighCore I have found that there is a issue with latest change in syntax and IDE support as following Commit.

https://github.com/dotnet/roslyn/commit/b49f841bdeeb0b620240d2435f5a0665012f6fce

And now my syntax looks like following.
using static System.Console;

namespace StaticClassUsing
{
     class Program
     {
         static void Main(string[] args)
         {
            WriteLine("With using statement");
         }
     }
}

If you see the code, You can see now they have static keyword in using statement.

Same way, There is another change in String Interpolation. Earlier the syntax was looking like following.
using System;
namespace StringInterpolation
{
      class Program
      {
           static void Main(string[] args)
           {
              string name = "Jalpesh Vadgama";

              //Old way of string concentaionation 
              Console.WriteLine("My name is" + name);
              Console.WriteLine("My name is {0}", name);

              //New way of doing this
              Console.WriteLine("My name is \{name}");
            }
       }
}


Now It’s look like following.
using System;
namespace StringInterpolation
{
     class Program
     {
          static void Main(string[] args)
          {
              string name = "Jalpesh Vadgama";

              //Old way of string concentaionation 
              Console.WriteLine("My name is" + name);
              Console.WriteLine("My name is {0}", name);

              //New way of doing this
              Console.WriteLine("My name is {name}");
          }
      }
}
If you see both code carefully now they have removed “\” as it was confusing with escape sequence. I have also updated my blog post and my repository at github at following location.

https://github.com/dotnetjalps/Csharp6NewFeatures

Hope you like it. Stay tuned for more!
Share:

0 comments:

Post a Comment

Your feedback is very important to me. Please provide your feedback via putting comments.

Support this blog-Buy me a coffee

Buy me a coffeeBuy me a coffee
Search This Blog
Subscribe to my blog

  

My Mvp Profile
Follow us on facebook
Blog Archive
Total Pageviews