Assign Tuple return in two variables

Asked

Viewed 212 times

2

Has a method that returns a tuple with two strings.

The return I want to record in two different variables, only I’m having to call the method twice to pick one item at a time.

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

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

You’d have to do it by calling once only?

2 answers

2


Has.

Just create a tuple to receive the return

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

Or else

var tupla = SearchTerra(artista, musica);

// Acessando
tupla.item1;
tupla.item2;

See working on . NET Fiddle.

2

Has.

var tupla = SearchTerra(artista, musica);
string retorno1 = tupla.item1;
string retorn2 = tupla.item2;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.