1. Top 10 Cool new features in C# 6.0
Website: http://csharpstar.com
Contact: admin@csharpstar.com
2. C#6.0NewFeatures
Await in a Catch and Finally Block
Dictionary Initializers
Exception Filters
Expression Bodied Function and
Property
Getter-Only Auto Properties
NameOf Expression
Null Conditional Operator
Static Using Syntax
Auto Property Initializer
String Interpolation
Website: http://csharpstar.com
Contact: admin@csharpstar.com
3. Auto Property Initializer
Website: http://csharpstar.com
Contact: admin@csharpstar.com
Before C# 6.0
In C# 6.0
Prior to C#6.0, we were using constructor to initialize the auto properties to non-default value. In C#6.0, you
can modify the Employee class and populate the property called EmployeeID with inline initialization.
4. Await in a Catch & Finally Block
Website: http://csharpstar.com
Contact: admin@csharpstar.com
In C# 6, now you can write
asynchronous code inside a
catch/finally block. This will help you
to log exceptions to a file or database
without blocking the current thread
5. Dictionary Initializer
Website: http://csharpstar.com
Contact: admin@csharpstar.com
In C# 5, you would initialize the Dictionary with a {“Key”, “Value”} Pair. Let’s look at below
example to understand it better. In C# 6, you can place the key between two square brackets
[“Key”] and then set the value of the key [“Key”] = “value”.
Before C# 6.0 In C# 6.0
6. Exception Filters
Website: http://csharpstar.com
Contact: admin@csharpstar.com
Exception Filters allow you to specify a condition for a catch block. In C#6.0, without entering the catch
block, you can check to see which condition met your exception.
7. Expression Bodied Function &
Property
Website: http://csharpstar.com
Contact: admin@csharpstar.com
Expression Bodied Functions are
functions with no statement body.
Instead, you implement them with
an expression following the
function declaration
8. Getter-Only Auto Properties
Website: http://csharpstar.com
Contact: admin@csharpstar.com
When you use auto implemented properties in C# 5 and lower, you must provide a get and set.
If you want the property value to be immutable, you can use the private accessor on the setter.
With C# 6, you can now omit the set accessor to achieve true readonly auto implemented
properties:
9. NameOf Expression
Website: http://csharpstar.com
Contact: admin@csharpstar.com
Name of Expression is a new feature introduced in C#6.0.In Enterprise level applications, we
handle exceptions at different levels. Showing a specific type name with an error message can
be an easy way to find the code block where the exception just occurred. But by adding this we
can’t show it to user because the type name can be changed anytime while refactoring but hard
coded string won’t change accordingly.
Before C# 6.0 In C# 6.0
10. Null Conditional Operator
Website: http://csharpstar.com
Contact: admin@csharpstar.com
Before C# 6.0 In C# 6.0
Most of us do not like NullReferenceException.
In C# 6.0, you can use ?. to check if an instance is null or not.
11. Static Using Syntax
Website: http://csharpstar.com
Contact: admin@csharpstar.com
Before C# 6.0 In C# 6.0
In C# 6, you can now add the using static qualifier and reference the WriteLine
method by itself as shown above.
12. String Interpolation
Website: http://csharpstar.com
Contact: admin@csharpstar.com
String Interpolation is a mechanism to concatenate two or more strings together. In older versions of C#,
we were using “+” operator or String.Format method to concatenate strings but in C# 6.0, Microsoft has
provided a feature named String Interpolation to concatenate strings.
Before C# 6.0 In C# 6.0
13. Summary
We have discussed all new and Interesting features of C# 6.0
For more interesting articles on .net & C#, you can visit:
http://csharpstar.com
http://easywcf.com
Contact us:
admin@csharpstar.com
Thank you !!