Microsoft has released C# 6.0 with new features. I am going to talking about one of the new C# 6.0 feature.
Following are list of new feature of C# 6.0
In C# 6.0 property initializer used to below way.
Here look at above example with Property Initializer feature.
Hope developer love this feature to easy and compact property initialization.
Following are list of new feature of C# 6.0
- Auto Property Initializer
- Primary Constructors
- Dictionary Initializer
- Declaration Expressions
- Static Using
- await inside catch block
- Exception Filters
- Conditional Access Operator to check NULL Values
Lets start talking about first feature. Here we are looking two example of Auto Property Initializer.
1) How we are initialization property before C# 6.0
2) How we are using Auto Property Initializer in C# 6.0
Start with classic property initialization. So lets go how to used in classic way.
Check about example, we have two property "Name" and "City". So in classic way we need to assign property value during object initialization it means under constructor.public class TestClass { public string Name { get; set; } public string City { get; set; } public TestClass() { //Assign value to property Name = "Kalpesh"; City = "Ahmedabad"; } }
public class TestClass { public string Name { get; } = "Kalpesh"; public string City { get; set; } = "Ahmedabad"; }
In C# 6.0 property initializer used to below way.
Here look at above example with Property Initializer feature.
Hope developer love this feature to easy and compact property initialization.
0 comments:
Post a Comment