To assign specific value to 1D array I’m using LINQ like so:
int[] nums = new int[20];
nums = (from i in nums select 1).ToArray<int>();
nums[0] = 2;
There is similar way to do so in 2D ([x,y]) array?
Or short way, without using nested loops?
LINQ doesn’t work particularly well with multi-dimensional arrays.
Jagged arrays aren’t too bad:
… but rectangular arrays don’t have any specific support. Just use loops.
(Note the use of
Enumerable.Repeatas a somewhat simpler approach to creating the 1-dimensional array, btw.)