using System using System Collections Generic using System Linq using

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace playground
{
class Matrix
{
private int _height;
private int _width;
private double[] _arr;
public Matrix(int height, int width)
{
this._height = height;
this._width = width;
this._arr = new double[height * width];
}
public double this[int a, int b]
{
get
{
return _arr[a * _width + b];
}
set
{
_arr[a * _width + b] = value;
}
}
public override string ToString()
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < _height; ++i)
{
for (int j = 0; j < _width; ++j)
{
sb.Append(this[i, j] + " ");
}
sb.Append("\n");
}
return sb.ToString();
}
}
class Program
{
static void Main(string[] args)
{
Matrix a = new Matrix(3, 3);
a[1, 2] = 2;
a[0, 1] = 5;
Console.WriteLine(a);
Console.ReadKey();
}
}
}