Assign Tuple return in two variables

2

It has a method that returns a tuple with two strings .

The return I want to write to two different variables, but I'm having to call the method twice to pick up one item at a time.

string retorno1 = SearchTerra(artista, musica).item1;

string retorno2 = SearchTerra(artista, musica).item2;

Would you like to do this by calling 1 time only?

    
asked by anonymous 12.04.2017 / 22:27

2 answers

2

Tem.

Just create a tuple to receive the return

(string retorno1, string retorno2) = SearchTerra(artista, musica);

Or

var tupla = SearchTerra(artista, musica);

// Acessando
tupla.item1;
tupla.item2;

See working in .NET Fiddle.

    
12.04.2017 / 22:29
2

Tem.

var tupla = SearchTerra(artista, musica);
string retorno1 = tupla.item1;
string retorn2 = tupla.item2;
    
12.04.2017 / 22:29