Let's Explore C# 6
Jaliya Udagedara
MVP (Visual C#)
.NET Framework
version
CLR version Released Year Visual Studio
version
C# Version
1.0 1.0 2002 Visual Studio .NET 1.0
1.1 1.1 2003 2003 1.2
2.0 2.0 2005 2005 2.0
3.0 2.0 2006 2005 2.0
3.5 2.0 2008 2008 3.0
4 4.0 2010 2010 4.0
4.5 4.0 2012 2012 5.0
4.5.1 4.0 2013 2013 5.0
4.5.2 4.0 2013 2013 5.0
4.6 Preview 4.0 2014 2015 Preview 6.0 Preview
C# 2.0 C# 3.0 C# 4.0 C# 5.0
Generics Implicitly typed variables
(var)
Named and optional
arguments
Async/Await
Partial Classes Object and collection
initializers
Dynamic Caller information
Static Classes Auto properties Covariance and
Contravariance in
Generics
Iterators Partial Methods
Anonymous Methods Extension Methods
Property Accessor
Accessibility
Lambda Expressions
LINQ
using System.Console;
class Program
{
static void Main(string[] args)
{
WriteLine("Hello C# 6.0");
}
}
public string FirstName { get; set; } = "Jaliya";
public string LastName { get; set; } = "Udagedara";
public string LastName { get; } = "Udagedara";
public DateTime DateOfBirth { get; set; }
public int Age => DateTime.Now.Year - DateOfBirth.Year;
public override string ToString() =>
string.Format("{0} {1}", FirstName, LastName);
public override string ToString() => "{FirstName} {LastName}";
public static Dictionary<int, Employee> GetEmployees()
{
return new Dictionary<int, Employee>()
{
[0] = new Employee() { FirstName = "Jaliya" },
[1] = new Employee() { FirstName = "John" },
[2] = new Employee() { FirstName = "Jane" }
};
}
try
{
}
catch (Exception ex) if (ex is NullReferenceException)
{
throw;
}
catch (Exception ex)
{
}
try
{
List<Employee> employees = null;
//some operation on null employees
}
catch (Exception ex) if (ex is NullReferenceException)
{
throw new NullReferenceException(nameof(employees));
}
catch (Exception ex)
{
}
WriteLine(employees?.Count);
try
{
int i = 0; Console.WriteLine(10 / i);
}
catch (Exception)
{
await LogAsync();
}
finally
{
await LogAsync();
}
struct Employee
{
public string FirstName { get; set; }
public string LastName { get; set; }
public Employee() : this("Jaliya", "Udagedara")
{
}
public Employee(string firstName, string lastName)
{
this.FirstName = firstName;
this.LastName = lastName;
}
}
• C# 6
Thank You!
http://www.jaliyaudagedara.blogspot.com/

Let's Explore C# 6

  • 1.
    Let's Explore C#6 Jaliya Udagedara MVP (Visual C#)
  • 3.
    .NET Framework version CLR versionReleased Year Visual Studio version C# Version 1.0 1.0 2002 Visual Studio .NET 1.0 1.1 1.1 2003 2003 1.2 2.0 2.0 2005 2005 2.0 3.0 2.0 2006 2005 2.0 3.5 2.0 2008 2008 3.0 4 4.0 2010 2010 4.0 4.5 4.0 2012 2012 5.0 4.5.1 4.0 2013 2013 5.0 4.5.2 4.0 2013 2013 5.0 4.6 Preview 4.0 2014 2015 Preview 6.0 Preview
  • 4.
    C# 2.0 C#3.0 C# 4.0 C# 5.0 Generics Implicitly typed variables (var) Named and optional arguments Async/Await Partial Classes Object and collection initializers Dynamic Caller information Static Classes Auto properties Covariance and Contravariance in Generics Iterators Partial Methods Anonymous Methods Extension Methods Property Accessor Accessibility Lambda Expressions LINQ
  • 8.
    using System.Console; class Program { staticvoid Main(string[] args) { WriteLine("Hello C# 6.0"); } }
  • 9.
    public string FirstName{ get; set; } = "Jaliya"; public string LastName { get; set; } = "Udagedara"; public string LastName { get; } = "Udagedara";
  • 10.
    public DateTime DateOfBirth{ get; set; } public int Age => DateTime.Now.Year - DateOfBirth.Year; public override string ToString() => string.Format("{0} {1}", FirstName, LastName);
  • 11.
    public override stringToString() => "{FirstName} {LastName}";
  • 12.
    public static Dictionary<int,Employee> GetEmployees() { return new Dictionary<int, Employee>() { [0] = new Employee() { FirstName = "Jaliya" }, [1] = new Employee() { FirstName = "John" }, [2] = new Employee() { FirstName = "Jane" } }; }
  • 13.
    try { } catch (Exception ex)if (ex is NullReferenceException) { throw; } catch (Exception ex) { }
  • 14.
    try { List<Employee> employees =null; //some operation on null employees } catch (Exception ex) if (ex is NullReferenceException) { throw new NullReferenceException(nameof(employees)); } catch (Exception ex) { }
  • 15.
  • 16.
    try { int i =0; Console.WriteLine(10 / i); } catch (Exception) { await LogAsync(); } finally { await LogAsync(); }
  • 17.
    struct Employee { public stringFirstName { get; set; } public string LastName { get; set; } public Employee() : this("Jaliya", "Udagedara") { } public Employee(string firstName, string lastName) { this.FirstName = firstName; this.LastName = lastName; } }
  • 18.
  • 19.

Editor's Notes

  • #4 C# 2.0 Generics Partial Classes C# 3.0 Implicitly typed variables (var) Object and collection initializers Auto properties Partial Methods Extension Methods Lambda Expressions LINQ C# 4.0 Named and optional arguments Dynamic Covariance and Contravariance C# 5.0 Async/Await Caller information
  • #5  Covariance Enables you to use a more specific type than originally specified. Ex:  IEnumerable<object> = IEnumerable<string> Contravariance Enables you to use a more generic (less derived) type than originally specified. Ex:  IEnumerable<string> = IEnumerable<object>
  • #6 Visual Studio Community 2013 Includes all the great functionality of Visual Studio Professional 2013 Terms Any individual developer can use Visual Studio Community to create their own free or paid apps Organization can use for the following scenarios: In a classroom learning environment Academic research Contributing to open source projects .NET Open Source and Cross-Platform ASP.NET and the C# compiler is already open sourced