Posts Tagged ‘c#’

final state of new features in C#6

July 14th, 2015 No comments

Ok, this topic has already been blogged to death, so my 2 cts flogging a dead horse here. From earlier posts reporting the new features back in 2014, some of the features have been dropped, and others have changed their syntax. So below, I add some gists detailing the most salient features in the new version of the language coming with VS 2015. I will pass on explaining each one, since a) the examples are easy to understand and b) there’s plenty of further explanation in the web and I am too lazy to replicate that. Automatic property initializers Self-explanatory here, I think.

Using static
String Interpolation Access properties directly in the string template, instead of the old tired way with the ordinal placeholders. Cleaner syntax and less prone to errors of placement and order. Notice the $.

Null comparison operator This is really a welcome change, instead of polluting code with null checks or implementing extension methods to avoid that. Now you can check for null references and null properties in a much cleaner and more natural way:
Inline Event Handlers

Exception filters This is a welcome change as well, for cleaner management of exceptions. You might have seen this is a previous syntax with if instead of when.
nameof Although this could be emulated before, it is nice to have this and avoid hardcoding parameter names.

Expression-bodied members
Awaitable catch and finallyThis works as well for finally blocks. New way of initializing dictionaries
And now, the stuff that has been dropped Stuff that has been dropped IEnumerable params This does not compile:

Declaration Expressions

Categories: c# Tags: