Can I assign each value in an array to separate variables in one line in C#? Here\'s an example in Ruby code of what I want:
irb(main):001:0> str1, str2
You can use named tuples with C# 7 now.
{
(string part1, string part2) = Deconstruct(new string[]{"hey","now"});
}
public (string, string) Deconstruct(string[] parts)
{
return (parts[0], parts[1]);
}
You can do this in C#
string str1 = "hey", str2 = "now";
or you can be fancy like this
int x, y;
int[] arr = new int[] { x = 1, y = 2 };