Is there a language construct similar to PHPs list() in C#?

allgenresaadn

New Member
PHP has a language construct \[code\]list()\[/code\] which provides multiple variables assignment in one statement.\[code\]$a = 0;$b = 0;list($a, $b) = array(2, 3);// Now $a is equal to 2 and $b is equal to 3.\[/code\]Is there a similar thing in C#?If not, is there any workaround which may help to avoid code like the following, without having to deal with reflection?\[code\]public class Vehicle{ private string modelName; private int maximumSpeed; private int weight; private bool isDiesel; // ... Dozens of other fields. public Vehicle() { } public Vehicle( string modelName, int maximumSpeed, int weight, bool isDiesel // ... Dozens of other arguments, one argument per field. ) { // Follows the part of the code I want to make shorter. this.modelName = modelName; this.maximumSpeed = maximumSpeed; this.weight= weight; this.isDiesel= isDiesel; /// etc. }}\[/code\]
 
Back
Top