New features of C # 6.0/7.0

Source: Internet
Author: User

New features of C # 6.0/7.0

C # 7.0 new features

  • Enhanced ref
    • You can pass a reference to a value variable ref int b = Ref A;
    • You can return a reference to return ref X for the returned value;
  • Automatically create out variables
  • Enhanced tuples (requires expansion pack support, Install-package system.valuetuple)
    • Named return value (int a, int b) GetValue () = (1, 2);
    • Attribute-valued var data = GetValue (); (with DATA.A, data.b access)
    • Direct-value (int a, int b) = GetValue (); (directly with a, B access)
  • Enhanced is
    • Type correct direct assignment A is int b
    • Type SELECT statement switch (a) case int b: ... case string C: ...
    • Enhanced type selection statement case int B when b < 0: ...
  • Local function (defines a small function in the body of the function, accessible only in the body of the function)
  • An enhanced function expression
    • Supports destructor = = Single call or assignment statement
    • Property expression Get = = variable; or set = = Variable =value?? "Default value";
  • Enhanced null exception handling (support??). throw new Exception (message);)
  • Enhanced asynchronous return type (VALUETASK<T>, requires expansion pack support, Install-package System.Threading.Tasks.Extensions)
  • Enhanced literal notation (int a = 123_456; int b = 0xab_cd_ef; Same as non-underlined values)
  • destructor deconstruct, calling method similar to tuple

C # 6.0 new features

    • Enhanced Property expressions
      • Read-only property public int a = 100;
      • Property default value public int c {get; set;} = 100;
      • Read-only properties and ReadOnly fields support assigning values in constructors
    • function expression, public int add (int a, int b) = = a + b;
    • NULL check operator
      • Int? Age = List?. FirstOrDefault ()?. Age; Non-NULL for subsequent operations (age must be a nullable type)
      • Int? Age = Users? [0]. Age; Non-null for index operation (age must be a nullable type)
    • Nameof expression, gets the name of the variable, function, class
    • Enhanced exception handling
      • Await is supported in catch and finally statement blocks
      • Catch support conditional expression, catch (Exception e) if (e.xxx = = XXX)
    • String embedding value, var user = $ "{Name} {age}"
    • Supports using static classes and then directly uses the methods in the class
    • Object initializer with index: New dictionary<string, int> {["a"] = 1, ["b"] = 1,};
    • Supports parameterless struct constructors (note that constructors are called only if the struct is obtained through new)

New features of C # 6.0/7.0

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.