????1) async / await
??????? async / await ????????????д?????????????????? UI ????????????????ò??????Щ??ж???????????????? web ??????async / await ??????????к????????
??????????? async / await ??????????????https://msdn.microsoft.com/zh-cn/library/hh191443.aspx
????2) ???? / ???? / ?????????趨??initializers??
????????????????顢?????????趨???????????????????????????????
????// ?????
????public class Employee {
????public string Name {get; set;}
????public DateTime StartDate {get; set;}
????}
????// ??ó????趨??????????
????Employee emp = new Employee {Name="John Smith"?? StartDate=DateTime.Now()};
????????????е?????????????п??????а?????????????Щ????????????????????????????????????????????????????????
???????????????趨?????????????https://msdn.microsoft.com/zh-cn/library/bb384062.aspx
????3) Lambda ??????ν????У?predicates??????У?delegates????????closures??
??????Щ??????????????????????????????? Linq ????????????????????????????????
??????????? Lambda ??????ν????С???к???????????????http://www.codeaddiction.net/articles/13/lambda-expressions-delegates-predicates-and-closures-in-c
????4) ?? – null ??????????Null coalescing operator??
?????????????? null ??????? ?????????????????????????????????
????// ?????? null
????var someValue = service.GetValue();
????var defaultValue = 23
????// ??? someValue ?? null ?????result ? 23
????var result = someValue ?? defaultValue;
??????????????????????????
????string anybody = parm1 ?? localDefault ?? globalDefault;
????????????????????????????????
????var totalPurchased = PurchaseQuantities.Sum(kvp => kvp.Value ?? 0);
??????????? ?? ?????????????????https://msdn.microsoft.com/zh-cn/library/ms173224.aspx
????5) $”{x}” – ??????????String Interpolation??- C# 6
????C# 6 ????????????????????????Ч????????????????????????
????// ??????
????var someString = String.Format("Some data: {0}?? some more data: {1}"?? someVariable?? someOtherVariable);
????// ?μ???
????var someString = $"Some data: {someVariable}?? some more data: {someOtherVariable}";
??????????????????д C# ??????????????÷?????
????6) ?. – null ???????????Null-conditional operator?? – C# 6
????null ?????????????????????????
????// ??? customer ?? customer.profile ?? customer.profile.age ? null ???????????? null
????var currentAge = customer?.profile?.age;
??????????? NullReferenceExceptions ???
??????????? ?. ?????????????????https://msdn.microsoft.com/zh-cn/library/dn986595.aspx
????7) nameof ???? – C# 6
?????μ? nameof ?????????????????????????????????????????????????????????????? Resharper????????????????????????????????????
????public void PrintUserName(User currentUser)
????{
????// ???????? currentUser ?????????????????????????е??????????
????if(currentUser == null)
????_logger.Error("Argument currentUser is not provided");
????//...
????}
???????????????????д??
????public void PrintUserName(User currentUser)
????{
????// ????????????????
????if(currentUser == null)
????_logger.Error($"Argument {nameof(currentUser)} is not provided");
????//...
????}
??????????? nameof ????????????????https://msdn.microsoft.com/zh-cn/library/dn986596.aspx
????8) ????????趨?? – C# 6
????????????????????趨???????????????????????????????
????public class User
????{
????public Guid Id { get; } = Guid.NewGuid();
????// ...
????}
???????????????趨???????????????????????? setter ??????????????????????????immutable????????????趨?????? C# 6 ????????????Primary Constructor?????????á??????????Primary Constructor ???????????????????????????????????????????????????????????
????9) as / is ?????
????is ??????????ж??????????????????????????????????????????????е??
????if (Person is Adult)
????{
????//do stuff
????}
????as ????????????????????????????????????????????????????? null??
????SomeType y = x as SomeType;
????if (y != null)
????{
????//do stuff
????}
????10) yield ?????
???????????? yield ??????????? IEnumerable ????????????????????? 2 ??η?????????? 8 ?η???2??4??8??16??32??64??128??256????
????public static IEnumerable<int> Power(int number?? int exponent)
????{
????int result = 1;
????for (int i = 0; i < exponent; i++)
????{
????result = result * number;
????yield return result;
????}
????}
?????????????????yield ???÷????????????????????????е???????統(tǒng)?????????????????????????????????