Im trying to implement a 2D array class using List of Lists. Can someone please help me to implement a get function similar to T this[int x, int y] function below to get all the elements in a column given by [int x,:] where x is the column. Returning as an array would be fine.
public class Matrix<T>
{
List<List<T>> matrix;
public Matrix()
{
matrix = new List<List<T>>();
}
public void Add(IEnumerable<T> row)
{
List<T> newRow = new List<T>(row);
matrix.Add(newRow);
}
public T this[int x, int y]
{
get { return matrix[y][x]; }
}
}
Or:
return matrix.Select(z=>z.ElementAtOrDefault(x));