New Feature in C# 7.1 – Inferred tuple element names

From past few years I have been keeping a close watch on ECMA scripts and seems C# is running neck to neck in importing features of ES-6

I have explained about Tuples in older Blog article here

C# 7.1 introduces a small feature enhancement to Tuple de-structuring.

To run below sample you need to install System.ValueTuple Nuget package


style="display:block; text-align:center;"
data-ad-format="fluid"
data-ad-layout="in-article"
data-ad-client="ca-pub-5021110436373536"
data-ad-slot="9215486331">


Continue reading

New Feature in C# 7.1 – default Literal expressions

default value expression provides a default value for a type and are very handy in generator functions and generic classes/methods.

This is how we can use default keyword till C# 7.0 i.e. as default(T) where T can be value type or reference type

private void btnDefaultExpressions_Click(object sender, EventArgs e)

{

string str = default(string); //Old way of defining default strings

 

var intValue = default(int);

 

string stringValue = default(string);

 

var nullableIntValue = default(int?);

}

Continue reading

New Feature in C# 7.1 – Async Main

“Main” is a special method while defining assemblies. It’s an entry point of an executable application. Main runs in static context by is called by operating system to load the program into memory. Main does so by defining a startup object or logic.

static class Program

{

        /// <summary>

        /// The main entry point for the application.

        /// </summary>

        static void Main(string[] args)

{

}

}

Continue reading

C# 7.1 New Features – Set up Visual Studio

In my past blog series, I have tried to explain all new features that shipped with C# 7.0. You can read about that here.

With Visual Studio Update 3 and version 15.3, C# 7.1 has been made available as well. This feature is not available by default and there are many ways you can turn this feature on. I will be writing a blog series on new features of C# 7.1 but before that lets understand how to set up support for 7.1 in visual studio.

There are 3 ways this feature can be enabled:

Way 1 – Changing Project Setting to target latest C# language

Continue reading