using System; class Matrix { private int rows; private int cols; private T[,] matrix; public Matrix() { rows = cols = 0; matrix = null; } public Matrix(int m, int n) { rows = m; cols = n; matrix = new T[m, n]; } public T this[int i, int j] { get { if (i < rows && j < cols) return matrix[i, j]; else throw new ArgumentOutOfRangeException(); } set { if (i < rows && j < cols) matrix[i, j] = value; else throw new ArgumentOutOfRangeException(); } } public int Rows { get { return rows; } } public int Cols { get { return cols; } } } public class Test { public static void Main() { Matrix myMatrix=new Matrix(3,2); myMatrix[0,0]=1; myMatrix[0,1]=2; myMatrix[1,0]=3; myMatrix[1,1]=4; myMatrix[2,0]=5; myMatrix[2,1]=6; for(int i=0; i<3; i++) { for(int j=0; j<2; j++) Console.Write(myMatrix[i,j] + "\t"); Console.WriteLine(); } } }