C # New Syntax collection

Source: Internet
Author: User

inline variables

When using Int.tryparst, declare the variable first for the out parameter

int D;

Int.tryparse (S,out D);

The use of inline variable notation can be as follows. Functionality simplifies writing

Int.tryparse (s,out int d)

$ "{Val1}-{val2}"

Functions like String.Format ("{0}-{1}", Val1,val2), which is parsed as a variable within {} in the string that begins with $.

Method of writing in the method

You can write some methods inside the method. js-like this write a function in the function

function ShowMsg (msg)

{

function validate () {}

}

/*

For example, the processing of a numeric string sort, if it is only a temporary use, you can not add a method, directly in the method to write a processing method on the line.

*/

Sort a number into a string

private string OrderList (String strnum)

{

}

Given string, returns the sorted result

public string Orderstringnum (String Str,int ordertype)

{

return this.orderlist (str);

}

Write directly within the method

Given string, returns the sorted result

public string Orderstringnum (String Str,int ordertype)

{

String OrderList (String strnum)

{

}

return orderlist (str);

}

Note: The method cannot be preceded by the private public, and it can only be used inside a declarative method. Similar to lambda, but it is essentially a method, and it is not as awkward to write as lambda.

C # New Syntax collection

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.