Perl has the ability to do:
my ($a,$b,$c,$d) = foo();
where foo
returns 4 variables, as opposed to assigning it one at a time. Is there something similar in C#?
To initialize a list in Python assign one with square brackets, initialize with the list() function, create an empty list with multiplication, or use a list comprehension. The most common way to declare a list in Python is to use square brackets.
You can also assign multiple variables to one value: a = b = c = 5; This code will set c to 5 and then set b to the value of c and finally a to the value of b .
You can declare several variables in one declaration statement, specifying the variable name for each one, and following each array name with parentheses. Multiple variables are separated by commas.
No, basically. Options:
object[] values = foo();
int a = (int)values[0];
string b = (string)values[1];
// etc
or:
var result = foo();
// then access result.Something, result.SomethingElse etc
or:
int a;
string b;
float c; // using different types to show worst case
var d = foo(out a, out b, out c); // THIS WILL CONFUSE PEOPLE and is not a
// recommendation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With