19
Let's Explore C# 6 Jaliya Udagedara MVP (Visual C#)

Let's Explore C# 6

Embed Size (px)

Citation preview

Page 1: Let's Explore C# 6

Let's Explore C# 6

Jaliya UdagedaraMVP (Visual C#)

Page 2: Let's Explore C# 6
Page 3: Let's Explore C# 6

.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

Page 4: Let's Explore C# 6

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

Page 5: Let's Explore C# 6
Page 6: Let's Explore C# 6
Page 7: Let's Explore C# 6
Page 8: Let's Explore C# 6

using System.Console;

class Program{

static void Main(string[] args){

WriteLine("Hello C# 6.0"); }

}

Page 9: Let's Explore C# 6

public string FirstName { get; set; } = "Jaliya"; public string LastName { get; set; } = "Udagedara";

public string LastName { get; } = "Udagedara";

Page 10: Let's Explore C# 6

public DateTime DateOfBirth { get; set; } public int Age => DateTime.Now.Year - DateOfBirth.Year;

public override string ToString() => string.Format("{0} {1}", FirstName, LastName);

Page 11: Let's Explore C# 6

public override string ToString() => "\{FirstName} \{LastName}";

Page 12: Let's Explore C# 6

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" }

};}

Page 13: Let's Explore C# 6

try{ } catch (Exception ex) if (ex is NullReferenceException) {

throw; } catch (Exception ex) {}

Page 14: Let's Explore C# 6

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) {}

Page 15: Let's Explore C# 6

WriteLine(employees?.Count);

Page 16: Let's Explore C# 6

try{

int i = 0; Console.WriteLine(10 / i); } catch (Exception) {

await LogAsync(); }finally{

await LogAsync(); }

Page 17: Let's Explore C# 6

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;

}}

Page 18: Let's Explore C# 6

• C# 6

Page 19: Let's Explore C# 6

Thank You!http://www.jaliyaudagedara.blogspot.com/