Essential C# language features

Some interesting features of C# 6

Automatically implemented properties

Object initializer

Caller information (CallerFilePathAttribute, CallerLineNumberAttribute, CallerMemberNameAttribute)

Collection initializer

Extension Methods

Lambda Expressions

Var keyword

Anonymous types

LINQ

Async and Await

Expression bodied methods like CalcMonthlyWage(int dailyWage) => dailyWage * 30

Conditional access /Null propogation / Elvis (?.)

Auto-property initializers (no need for private set)

Primary constructor (adding constructor params at class lvl)

Declaring OUT param in method call (rather than separately)

Await can be called in catch/finally block, allowing async exception handling

Putting static class names in USING statements

String interpolation ({someval})

Exception filters – major new feature, taking advantage of existing CLR feature.  Syntactic sugar of allowing catch (Exception e) when (e.Code == 42).  But not simply syntactic sugar, it does not unwind the stack (which is how we lose state info on method that rethrew the exception).  If you use throw, vs throw ex; the stack is not unwould.  You can actually call a method as long as it returns a boolean

Advertisements
This entry was posted in Uncategorized and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s