mini training - c# 6
TRANSCRIPT
MAXIME LEMAITRE – 26/11/2015
C# 6… meet roslyn …
Agenda
• New features• Bonus• Demo• Conclusion• Question Released July 20, 2015
with .net 4.6, Roslyn, VS 2015
Auto-Property Initializers
You can initialize an auto-implemented property inline. You no longer have to declare a setter, providing a new way to implement an immutable property
auto-implemented properties were introduced in C# 3.0.
Read-Only Auto-Properties
You no longer have to declare a setter for auto-implemented properties. If no setter is declared, the property is immutable everywhere except the type’s constructor
Null-Conditional Operator
If student is null, address will simply be assigned null, and no NullReferenceExeception will occur. This becomes more useful with deeper object graphs.
Using Static Directives
Using static directives are a new kind of using directive which brings static members of types directly into scope.The intention of this feature is to improve code readability by eliminating unnecessary and/or redundant type identifiers
String Interpolation
typically to concatenate strings you would either use the “+” operator or composite formatting with a method such as String.Format
With interpolated string expressions, you have a string with contained expressions that are replaced with the expressions’ results. You have to prefix your string literal with a dollar sign ($)
nameof Expressions
Now with nameof expressions, you don’t have to use string literals and the compiler will be able to warn you if you are using an incorrect name.
Some examples of where nameof expressions may be useful include:• Throwing exceptions during parameter validation• Passing an action name when setting up MVC action links• Needing to pass the name of a property when firing a property changed event in
a class that implements INotifyPropertyChanged• Passing the name of a property when registering a XAML dependency property• Including a variable, type, or member name when logging
Dictionary Initializers
slightly cleaner syntax for dictionary initialization
Expression Bodied Functions and Properties
You can now declare functions and properties as a lambda expression, without the need for a statement block. Intended for simple implementations, the new syntax is more concise in that it eliminates the need for some of the curly braces and the use of an explicit return statement.
Await in Catch and Finally Blocks
Ability to write asynchronous code (use the await keyword) in catch and finally blocks
Exception Filters
Now, through the use of the “when” keyword, we can specify a condition for any catch block. Execution will only drop into a catch block if the condition is satisfied. This allows us to filter exceptions on things other than just the exception type.
Conclusion
C# 6.0 isn’t a radical revolution in C# programming. This version will change the way you write C# code in specific scenarios. But Roslyn add new possibilities in C# 7 is on track…
Bonus : Live code analysis (light bulbs)
The new Roslyn compiler for C# and Visual Basic not only provides faster compile times—it also enables completely new scenarios such as live code analysis, which provide rich and customizable feedback and suggestions directly inside the code editor as you type
Demo
Questions
References
• https://medium.com/@JoeIngeno/c-6-0-features-you-should-know-f8d9056f3330• https://msdn.microsoft.com/en-us/magazine/dn802602.aspx• https://github.com/dotnet/roslyn/wiki/New-Language-Features-in-C%23-6 • https://github.com/dotnet/roslyn/issues/2136 (C# 7 work list of features) • http://stackoverflow.com/questions/27093908/how-to-enable-c-sharp-6-0-feature-in-visual-studio-2013 • https://github.com/dotnet/roslyn • https://www.nuget.org/packages/Microsoft.Net.Compilers/ (standalone compiler via nuget)
About Us• Betclic Everest Group, one of the world leaders in online
gaming, has a unique portfolio comprising various complementary international brands: Betclic, Everest Poker/Casino, Bet-at-home, Expekt, Imperial Casino, Monte-Carlo Casino…
• Through our brands, Betclic Everest Group places expertise, technological know-how and security at the heart of our strategy to deliver an on-line gaming offer attuned to the passion of our players. We want our brands to be easy to use for every gamer around the world. We’re building our company to make that happen.
• Active in 100 countries with more than 12 million customers worldwide, the Group is committed to promoting secure and responsible gaming and is a member of several international professional associations including the EGBA (European Gaming and Betting Association) and the ESSA (European Sports Security Association).
We want our Sports betting, Poker, Horse racing and Casino & Games brands to be easy to use for every gamer around the world. Code with us to make that happen.
Look at all the challenges we offer HERE
Check our Employer Page
Follow us on LinkedIn
WE’RE HIRING !