The new C# and two good things.

I have installed Visual Studio 2015 on a Virtual machine and it is GREAT..! I am making a post on it with screenshots but for now let me tell about some cool Visual C# 2015 preview features

1 Auto-Properties with initializers.
Now you can code something like

public int id { get; } = 15;

Yes this is coming. And setter is not a must while you implement though the property is still assignable at declaration time with a setter like the below

public int id { get; set; } = 17;

2 Say no to Console.WriteLine();
This is another cool thing, and a dream comes true for us all. Now you can

using System.Console;

and this will never return and error and after this you can directly

WriteLine("This is awesome");

This is not only for this but we can use any static classes in using and avoid their prefixes when we call their methods. Another good example is

using System.Math;

and just call any method in the Math class which is static.

2.1 Can await in the body of catch / finally clause

private static async Task<string[]> ReturnSomeStringPlease()
        using (var reader = File.OpenText("Words.txt"))
            var s = await reader.ReadToEndAsync();
            return s.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
        using (var reader = File.OpenText("someotherWords.txt"))
            var s = await reader.ReadToEndAsync();
            //this has happened in my life time... yaaaaaayyy!!
            return s.Split(new[] { Environment.NewLine }, StringSplitOptions.None);

There are even more things. I will write about them soon.

One thought on “The new C# and two good things.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s