View
542
Download
2
Category
Tags:
Preview:
Citation preview
Let's Explore C# 6
Jaliya UdagedaraMVP (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
Recommended