I have just installed Visual Studio 2015 and was playing with C# 6.0.
It has loads of new features supported out of the box that are mainly for making the code clean and lean.
Some of the features supported by C# 6.0 are already listed in the following link: What is new in C# 6.0.
I tried to run a sample application that uses some of the new features and found it very interesting.
Null checks using the conditional operator (? :) (unofficially called the Elvis operator) and String.Format using \{} (also called string interpolation) and loads of such things are supported by the Framework out of the box.
Here is a sample code that can get you started:
- using System.Console;
- namespace VS2015Sample
- {
- class Program
- {
- static void Main(string[] args)
- {
- string version = ".Net 4.6";
- object vsEditor = null;
- WriteLine("Sample executing with VS 2015 on \{version} \{vsEditor?.ToString()}");
- vsEditor = "VS 2015";
- WriteLine("Sample executing with VS 2015 on \{version} \{vsEditor?.ToString()}");
- ReadLine();
- }
- }
- }
If you see in the code above, I am not using Console.WriteLine or Console.ReadLine anywhere. I am also not having null checks for displaying the vsEditor details. Also, String.Format is not used anywhere for formatting display strings.
The output of the code above will be as depicted below:
C# 6.0 looks promising and will help the developer fraternity with many simple tricks.
Happy coding!