This paper mainly introduces the algorithm in C #: The related knowledge of exchange, it has good reference value. Let's take a look at the little series.
Swapping the values of 2 variables is like swapping drinks from two cups: a glass full of milk and a cup full of coffee, how can you exchange it?
The exchange of variables is also true. The exchange of two variables also requires an "empty cup", which is the intermediate variable :
String a= "vibration";//the first variable string b= "Wenfeng";//second variable string temp;//intermediate variable//First step: Assign variable A to the middle variable temp=a;//as milk pour empty cup//second step: Assign variable B to variable aa=b ;//As coffee into the Milk Cup//Third step: Assign the middle variable to the variable bb=temp;//as the milk in the empty cup into the coffee cup//At this time the exchange is complete, variable a stores "Wenfeng", b Storage "vibration just"
The process of solving practical problems is called " algorithm ", and switching is one of the most common algorithms.
Another example:
Namespace test{ class program { static void Main (string[] args) { string child = "Beauty";//Boy name String girl = "Wei Qiang";//girl name string temp;//middle variable temp = boy;//assigns the boy's name to temp boy = girl;//assigns the girl's name to the boys Girl = temp;//assigns the name in the temp to the girl Console.WriteLine ("The boy is called" +boy+ "the girl is called" +girl);}}
The result of the operation is: