Skip to content

History

Kota edited this page Feb 15, 2019 · 8 revisions

C#

1.0 (2002)

  • Hello, World!

2.0 (2005)

  • Generic

3.0 (2007)

  • cs => cs.Linq

4.0 (2010)

  • dynamic

5.0 (2012)

  • async

6.0 (2005)

Language Features

  • Auto Property Initializer
public Guid Id { get; } = Guid.NewGuid();
  • Primary Constructor
public class Money(string currency, decimal amount)
{
  public string Currency { get; } = currency;
  public string Amount { get; } = amount;
}
  • using Static Typename
using System.Console;
class Program
{
  public static void Main()
  {
    WriteLine("Hello World!");
  }
}
  • Dictionary Initializers
var _users = new Dictionary<string, string>() { 
  ["admin"] = "Ram",
  ["guest"] = "Sham"
}
// earlier
var _users = new Dictionary<string, string>() { 
  { "admin", "Ram" },
  { "guest", "Sham" }
}

  • Event Initializer : Wiring up an event while creating the object
  • Numeric Literals
public byte Code { get; } = 0b1100;
public long Length { get; } = 1_000_000_000;
  • Declaration Expression
foreach (var n in var odd = numbers(n +. n %2 == 1).ToList())
{
}

// old
var amount = 0;
decimal.TryParse("10.0", out amount);

// new
decimal.TryParse("10.0", var out amount);
  • Conditional Access
var name = action?.Method?.Name ?? "no name";
  • Await in Catch block

Compiler Features

Clone this wiki locally