fork download
  1. using System;
  2. class Matrix<T> {
  3. private int rows;
  4. private int cols;
  5. private T[,] matrix;
  6.  
  7. public Matrix() {
  8. rows = cols = 0;
  9. matrix = null;
  10. }
  11.  
  12. public Matrix(int m, int n) {
  13. rows = m;
  14. cols = n;
  15. matrix = new T[m, n];
  16. }
  17.  
  18. public T this[int i, int j] {
  19. get {
  20. if (i < rows && j < cols)
  21. return matrix[i, j];
  22. else
  23. throw new ArgumentOutOfRangeException();
  24. }
  25. set {
  26. if (i < rows && j < cols)
  27. matrix[i, j] = value;
  28. else
  29. throw new ArgumentOutOfRangeException();
  30. }
  31. }
  32.  
  33. public double Rows {
  34. get { return rows; }
  35. }
  36.  
  37. public double Cols {
  38. get { return cols; }
  39. }
  40. }
  41.  
  42. public class Test
  43. {
  44. public static void Main()
  45. {
  46. Matrix<double> myMatrix=new Matrix<double>(3,2);
  47. myMatrix[0,0]=1.5;
  48. myMatrix[0,1]=16;
  49. myMatrix[1,0]=18;
  50. myMatrix[1,1]=3.6;
  51. myMatrix[2,0]=7.1;
  52. myMatrix[2,1]=2.9;
  53.  
  54. for(int i=0; i<3; i++)
  55. {
  56. for(int j=0; j<2; j++)
  57. Console.Write(myMatrix[i,j] + "\t");
  58. Console.WriteLine();
  59. }
  60. }
  61. }
  62.  
Success #stdin #stdout 0.06s 32544KB
stdin
Standard input is empty
stdout
1.5	16	
18	3.6	
7.1	2.9