C# From Beginning till 6.0

What is C#: C# is an Object-Oriented language

Evolution of C#: Following image shows the journey of C# till 6.0

c_evolution

C# 6.0 new features:

  • Auto-Property Initializer: As name suggests, it allows developer to set the value of the property when it is declared in class. Earlier, one need to set value in the constructor

public class Blog

    {

        public string Name {get; set;}

        public Blog ()

        {

            Name = “Name”;

        }

}

But in C# 6.0 this can be like this

public class Blog

  {

          public string Name {ge; set;} = “Name”;

 }

One can also set different accessor for ‘get, set’ properties

public string Name {get; protected set;} = “Name”;

One can initialize read-only properties

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

  • ‘Static Using’ namespace: In C# 6.0, one can add using static qualifier in the reference
  • Dictionary Initializer: One can map the key/indexer directly at the time of dictionary object initialization.

Dictionary<int, string> SampleDcitionary = new Dictionary<int, string>

{

{1,”Sample1″ },

{2,”Sample2″ },

{3,”Sample3″ },

{4,”Sample4″ },

{5,”Sample5″ }

};

  • String Interpolation: Now one can put expression directly into string literal.

String TestString = $”Here expression is added in string : {Name}”;

  • Null Conditional Operator: Checking null value has become lot easier by performing a member access (.?)

int? length = blogs?.Length; // null if blogs is null

Blog first = blogs?[0];  // null if blogs is null

int? count = blogs?[0]?.Pages?.Count();  // null if blogs, the first blogs, or Pages is null

Author: Rupesh

Hi! I'm Rupesh, technophile and funophile. I'm an Application Developer, Solution Architect and IT-Consultant. I am a Microsoft certified Professional (MCP,MCSD,MCSA,MCSE). My hobby includes reading, writing, tennis, bollywood and cricket

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