PDA

View Full Version : سوال: ساخت کلاس برای ارایه های دو بعدی



G.EOTW
جمعه 08 اسفند 1393, 15:17 عصر
سلام دوستان. من یک برنامه باید بنویسم که 2 ارایه دو بعدی را با هم جمع کنه با استفاده از کلاس ها .
در کلاس زمان گرفتن مقدار برای ارایه مشکل دارم . لطفا کمک کنید.





class matrix
{

private int row;
private int colums;
private int[][] array;

public matrix(int row , int colums)
{
this.row = row;
this.colums = colums;

int[,] array = new int[row, colums];

}
public void input()
{
string t;

for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{

Console.Write("array {0},{1}:", i, j);
t = Console.ReadLine();

array[i][j] = int.Parse(t);


}
}

Hamid2547
جمعه 08 اسفند 1393, 16:53 عصر
class matrix
{

private int row;
private int colums;
public int[,] array;

public matrix(int row, int colums)
{
this.row = row;
this.colums = colums;

array = new int[row, colums];

}

private class ourInput
{
public void input()
{
string t;
var myMatrix = new matrix(2, 2);
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{

Console.Write("array {0},{1}:", i, j);
t = Console.ReadLine();

myMatrix.array[i,j] = int.Parse(t);


}
}
foreach (var number in myMatrix.array)
{
Console.WriteLine(number);
}
}
}
class Program
{

static void Main(string[] args)
{
ourInput myInput = new ourInput();
myInput.input();

}
}

ravaei
جمعه 08 اسفند 1393, 18:38 عصر
این قسمت کد رو تغییر بده به کد زیر :






Console.Write("array {0},{1}:", i, j);
t = Console.ReadLine();
array[i][j] = convert.toint32(console.readline());