In PHP you can write
$arr = array(1,2);
list($a, $b) = $arr;
Which is basically the equivalent of
$a = $arr[0];
$b = $arr[1];
Is there an equivalent in C#?
Just bugs me because so often I write things like
var split = action.Split('.');
string controllerName = split[0];
string actionName = split[1];
And split is just a throw-away variable that I can never think of a decent name for. “chunks”, “bits”, “pieces”, “parts”,… all meaningless jibberish.
You could write your own method, like:
I wouldn’t recommend it, though…You’d have to be careful about having the right number of parameters, and I don’t think there’s a way to do an arbitrary size – C# has the concept of “params array” in the signature, but I don’t think you can do it with “out” parameters.