C# Changes for the ASP.NET MVC Developer
C# 6 #
Released Jul 20, 2015
Along with Roslyn Compiler, .NET 4.6, and Visual Studio 2015
Summary #
C#6 focuses on streamlining common issues that require clumsy work-arounds that clutter the code.
Null-conditional operator, string interpolation, getter only auto-properties, static using statements, expression-bodied methods, and index initializers all contribute significantly towards increasing readability of C# code, reducing the number of lines and complexity of code, and improving the elegance and ease of expressing the programmer’s intent.
List of Features #
Null-conditional Operators
int? length = customers?.LengthString interpolation
var s = $“{p.Name} is {p.Age} year{{s}} old”;Getter-only auto-properties and initializers for auto-properties
public string First { get; } = “Jane”;Nameof Expressions
if (x == null) throw new ArgumentNullException(nameof(x));Static using statements (watch out for extension methods)
using static System.Math;Index Initializers for Dictionaries
Expression-bodied function members i.e. declare a method with =>
public Point Move(int dx, int dy) => new Point(x + dx, y + dy);Exception Filters (catch if case is true)
Await in Catch/Finally blocks
Can now call an extension method named Add from collection initilializer
Improved overload resolution
Detailed Explanation of New Features #
C# 5 #
Summary #
C# 5 unlocks an entirely new paradigm of programming with the async and await keywords. These keywords enable asynchronous programming (think javascript click handlers) to be written in a synchronous mental model, enabling much cleaner, easier to follow logic lines.
Caller information changes are also significant, and likely to be used heavily by third-party libraries such as Log4Net, and NLog to more accurately and easily determine which methods and line numbers were involved when the trace message was recorded.
List of Changes #
- Async and Await Keywords for asynchronous programming
- Caller Information - Allowing better tracing/debugging tools to be written
Details #
[4]: