Initializing Objects With Shorthand C#

Sometimes it is more efficient to create an Object, List, Array, or whatever with shorthand code rather than fully defining an object. If you have not heard of shorthand code, it is simply an object that is defined in one or two lines of code versus using several lines as you would normally do as a beginner or member of a larger team. Shorthand produces less lines of code, but it is not as easy to read (which may be a problem if you are on a team.)

Lets take a look at an example of an Object created in shorthand vs full:

Dictionary

Example 1

Dictionary<int, StudentName> students = new Dictionary<int, StudentName>()
{
    { 111, new StudentName {FirstName="Sachin", LastName="Karnik", ID=211}},
    { 112, new StudentName {FirstName="Dina", LastName="Salimzianova", ID=317}},
    { 113, new StudentName {FirstName="Andy", LastName="Ruth", ID=198}}
};

Example 2

new Dictionary<String, String>(){{"class","GridControl"}}