0

How do you exchange the value of a variable to another variable like the value of variable a will go to variable b in C#?

I need a hand

21st Jul 2018, 1:14 AM
Harold Bubuli
Harold Bubuli - avatar
2 odpowiedzi
+ 4
Which language? Typically looks something like var a = var b, but exact form may depend on the language.
21st Jul 2018, 2:06 AM
Tony
Tony - avatar
+ 3
In Python it is very easy: a,b = b,a In most other languages, you need a temporary variable, to store the value of one, so it won't get lost. eg if a=1, b=2: tmp = a // a=1, b=2, tmp=1 a = b // a=2, b=2, tmp=1 b = tmp // a=2, b=1, tmp=1 swapped
21st Jul 2018, 2:13 AM
Matthias
Matthias - avatar