C # function returns a method of multiple values

Sometimes we need a function to return multiple values. On the Internet, it is mostly implemented with out. I personally like to use the tuple method.

Tuple is a tuple, which supports up to 7 elements, and more methods such as nesting are needed.

The method of using tuples to define functions is as follows:

public static Tuple<string,string span>> TupleFun()

{
string[] T = {'hello','world'};
Tuple
<string, string> tup = new Tuple<string, string span>>(T[0], T[2]);
return tup;
}

Tuples also support multiple types of values.

public static Tuple <string,int> TupleFun ()

{
string T = ‘hello’;
int q = 6;
Tuple
<string, int> tup = new Tuple<string, int span>>(T, q);
return tup;
}

When calling the function, use Item* to call the elements in the tuple.

var tuple = TupleFun();

print(tuple.Item1);
print(
int.Parse(tuple.Item2));

public static Tuple<string,string> TupleFun()

{
string[] T = {'hello','world'};
Tuple
<string, string> tup = new Tuple<string, string span>>(T[0], T[2]);
return tup;
}

public static Tuple<string,int> TupleFun()

{
string T = ‘hello’;
int q = 6;
Tuple
<string, int> tup = new Tuple<string, int span>>(T, q);
return tup;
}

var tuple = TupleFun();

print(tuple.Item1);
print(
int.Parse(tuple.Item2));

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3044 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.