Asp.net string operators + and + =

Source: Internet
Author: User

In java, the ++ and ++ = operators can be used as character links in special context, in addition to the functions described earlier. So they are also called string operators, which have some interesting behaviors. If the expression starts with a string, all subsequent operands must be string type (the compiler automatically transmits the Character Sequence in double quotation marks to a string ):

Public class stringoperators {

Public static void main (string [] args ){

Int x = 0, y = 1, z = 2;

String s = "x, y, z ";

System. out. println (s + x + y + z );

System. out. println (x + "+ s );

S + = "(summed) = ";

System. out. println (s + (x + y + z ));

System. out. println ("" + x );

}

}

Output

X, y, z 012

0 x, y, z

X, y, z (summed) = 3

0

It should be noted that the first line outputs 012 rather than sum 3, because the compiler automatically converts them into the string form, and the last part appends a string to s with ++ =, and use parentheses to control the compiler conversion so that they can sum smoothly.

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.