ASP.NET C# 6.0 Features that every ASP.NET Developer
should know about it.
1.
Auto-property initializes
public
int
ID { get;
set;
}
public
bool
Role { get;
set;
} = true;
public
string
Name { get;
set;
} = string.Empty;
public
DateTime CreatedDate { get;
set;
} = DateTime.Now;
2.
Expression bodied members
public
string
Name => string.Format("{0} {1}", FirstName, LastName);
3.
Getter-only auto-properties
public
DateTime BirthDate { get;
}
4.
String interpolation
public
string
FullName => $"{FirstName} {LastName}";
5.Null-conditional
operators
//Before
var customer = new List<Customer>();
var name = string.Empty;
if(customer.FirstOrDefault()
!= null)
{
name = customer.First().Name;
}
//RIGHT NOW
var customer = new List<Customer>();
var name = customer.FirstOrDefault()?.Name;
5.
Index initializes
//Before
Dictionary<int, string>
dictObj = new
Dictionary<int,
string>
{
{1, "S1" },
{2, "S2" },
{3, "S3" }
};
//After
Dictionary<int, string>
dictObj = new
Dictionary<int,
string>
{
[1] = "S1",
[2] = "S2",
[3] = "S3"
};
Reference
link