Tuesday, October 13, 2015

Photos from Austin .Net Users Group October 12, 2015 - What's New in C# 6.0



Jimmy Bogard addressed 35 people at the Austin .Net Users Group on C# 6.0 and the new C# compiler.  The original C# compiler was written in 2000 in C++.  Roslyn, a completely rewritten compiler coded in C# is currently available.
Roslyn is only usable from VS 2015.

Roslyn being developed in the open at github.com by Microsoft.

It is multi-threaded.

Roslyn makes implementing new language features much easier.
Jimmy showed how C# 6.0 is used in his project AutoMapper.

Here are my unedited random notes on new features in C# 6.0:


0. private setter:
public Type SourceType {get; } //implies setting only in constructor

1. auto-initialize
public string FirstName { get; set; } = "Joe";
public string CreationDate {get;set;} = DateTime.Now;

field or property?  if using variable outside a class use property

2. Expression Body Function Members:
public string FullName { get { return FirstName + " " + LastName; }
replaced with 
public string FullName => FirstName + " " + LastName;
Can be used for methods as well:
public string GetFullName() => FirstName + " " + LastName;

3. Using Static - pulls in all possible methods from class to be used in class
using static System.Console;
WriteLine("....");
 using static system.math;
Round()
using System.Linq.Enumerable

4. Null Propagating Operator (The Elvis Operator) ?.
var x = source?.GetType() ?? sourceType;

5. String Interpolation - use instead of string.Format()
return $"Trying to map {SourceType.Name} to {DestinationType.Name}";

6. nameof()
throw new ArgumentNulException(nameof(context));

7. Index Initializer
static Customer() {
Dictionary customers = new {
[0] = new Customer(),
[10] = new Customer()
}
 }

8. Exception Filter

catch(Exception ex) when System.Threading.Thread.CurrentPrincipal.Indent.Name != "asdf"


9. await/catch/finally



No comments: