using System.Collections.Generic;
private static int[, ] _matrix = new int[2, 3];
public static void Add(List<int> lst)
var height = _matrix.GetLength(0);
var width = _matrix.GetLength(1);
if (lst.Count != width * height)
throw new ArgumentException($"The number of elements in lst ({lst.Count}) is not equal to the matrix {width * height}");
for (var y = 0; y < height; y++)
for (var x = 0; x < width; x++)
_matrix[y, x] = lst[x + width * y];
public static void Add2(List<int> lst)
var width = _matrix.GetLength(0);
var height = _matrix.GetLength(1);
if (lst.Count != width * height)
throw new ArgumentException($"The number of elements in lst ({lst.Count}) is not equal to the matrix {width * height}");
Buffer.BlockCopy(lst.ToArray(), 0, _matrix, 0, lst.Count * sizeof(int));
public static void Write()
var height = _matrix.GetLength(0);
var width = _matrix.GetLength(1);
for (var y = 0; y < height; y++)
for (var x = 0; x < width; x++)
Console.Write(_matrix[y, x]);
public static void Main()
Add(new List<int>{1, 2, 3, 4, 5, 6});
Add2(new List<int>{1, 2, 3, 4, 5, 6});