Category Archives: C# 6

C# 6 – nameof operator

nameof returns the name of the variable, type, or other symbol as a string. Here is an example.

Posted in C# 6 | Leave a comment

C# 6 – string interpolation

String interpolation offers a alternative to string.Format and can be used as such:     string s = $”It is {DateTime.Now.DayOfWeek} today.”;                  

Posted in C# 6 | Leave a comment

C# 6 – Index initializers

Index initializers allow single-step initialization of any type that exposes an indexer.     int[] _someintarray = {1, 2, 3, 4, 5}; var dict = new Dictionary<int, string>() { [3] = “three”, [10] = “ten” };

Posted in C# 6 | Leave a comment

C# 6 – Property initializers

Property initializers let’s you assign an initial value to an automatic property.     public DateTime DateOpened { get; set; } = DateTime.Now; Can also defined a read-only property as follows:     public DateTime DateOpened { get; } = … Continue reading

Posted in C# 6 | Leave a comment