Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

Use tuple to swap values c#

//Before C# 7's tuples, the standard way to swap two variables was something like:

var foo = 5;
var bar = 10;

var temp = foo;
foo = bar;
bar = temp;

//But now we can use

(foo, bar) = (bar, foo);

//It's on one line and it's prettier.
 
PREVIOUS NEXT
Tagged: #Use #tuple #swap #values
ADD COMMENT
Topic
Name
7+6 =