Exchange 2 variable values

Source: Internet
Author: User

If there are 2 variables for name1= Li Jing, name2= Zhang Yi. To Exchange 2 variable values, the result is name1= Zhang Yi, name2= Li Jing.

string name1= "Li Jing "; //Define a variable and assign a value

string name2= "Zhang Yi "; //Define another variable and assign a value

String temp=name1; //Fixed a variable equal to the transfer function temporarily help to store the first variable value already defined

name1=name2; //assigns a second variable value to the first variable name

Name2=temp; //Assign the variable stored in the relay function to the second variable name

Console.WriteLine ("Name1={0} Name2={1}", name1,name2); //Output variable

Console.readkey ();

The output is:name1= Zhang Yi

name2= Li Jing .

Exchange 2 variable values

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.