C# 6 specification in a Console Application

This program inside almost all the new C# 6 features. By look at the https://github.com/dotnet/roslyn/wiki/New-Language-Features-in-C%23-6 you might have problem to put the code into an application, especially if you just started using C# no too long ago.

The console application below consists of:

1.    Initializers for auto-properties

2.    Getter-only auto-properties

3.    Expression-bodied function members

4.    Using static

5.    Extension methods

6.    Null-conditional operators

7.    String interpolation

8.    nameof expressions

9.    Index initializers

The 2 features below I need to construct it as other program and post it.

1.    Index initializers

2.    Await in catch and finally blocks

The console program as follow.

using System;

using System.Collections.Generic;

using System.Linq;

// Using static

using static System.DayOfWeek;

using static System.Linq.Enumerable; // The type, not the namespace


namespace ConAppCSharp6



    public class Customer


        // Initializers for auto-properties

        public string First { get; set; } = “Jane”;

        public string Last { get; set; } = “Doe”;

        public string Age { get; set; }

        // Getter-only auto-properties

        public string Name { get; } = “Unknown”;


        public Customer()



        public Customer(string first, string last)


            Name = first + ” “ + last;


        // Expression-bodied function members

        public void Print() => Console.WriteLine(First + ” “ + Last);




    class Program


        static void Main(string[] args)


            String x = null;

            Customer p = new Customer();

            List<Customer> customers = new List<Customer>();

            Console.WriteLine(Friday – Monday);


            // Extension methods

            var range = Range(5, 17);                // Ok: not extension

            //var odd = Where(range, i => i % 2 == 1); // Error, not in scope

            var even = range.Where(i => i % 2 == 0); // Ok


            // Null-conditional operators

            Customer first = customers?[0];  // null if customers is null

            // String interpolation

            var s = $”{p.Name} is {p.Age} year{{s}} old”;

            // nameof expressions

            if (x == null) throw new ArgumentNullException(nameof(x));

            // Index initializers

            var numbers = new Dictionary<int, string>


                [7] = “seven”,

                [9] = “nine”,

                [13] = “thirteen”





About chanmingman

Since March 2011 Microsoft Live Spaces migrated to Wordpress (http://www.pcworld.com/article/206455/Microsoft_Live_Spaces_Moves_to_WordPress_An_FAQ.html) till now, I have is over 1 million viewers. This blog is about more than 50% telling you how to resolve error messages, especial for Microsoft products. The blog also has a lot of guidance teaching you how to get stated certain Microsoft technologies. The blog also uses as a help to keep my memory. The blog is never meant to give people consulting services or silver bullet solutions. It is a contribution to the community. Thanks for your support over the years. Ming Man is Microsoft MVP since year 2006. He is a software development manager for a multinational company. With 25 years of experience in the IT field, he has developed system using Clipper, COBOL, VB5, VB6, VB.NET, Java and C #. He has been using Visual Studio (.NET) since the Beta back in year 2000. He and the team have developed many projects using .NET platform such as SCM, and HR based applications. He is familiar with the N-Tier design of business application and is also an expert with database experience in MS SQL, Oracle and AS 400.
This entry was posted in .Net, Community and tagged , , , , . Bookmark the permalink.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

This site uses Akismet to reduce spam. Learn how your comment data is processed.