Обработка динамических массивов - C#
Формулировка задачи:
В общем, есть программа которая работает через массив static object[,] array;, нужно сделать чтобы она работала через int[][] A = new int[0][];
Решение задачи: «Обработка динамических массивов»
textual
Листинг программы
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- static int[][] array;
- private void label1_Click(object sender, EventArgs e)
- {
- }
- private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
- {
- }
- private void label2_Click(object sender, EventArgs e)
- {
- }
- private void button3_Click(object sender, EventArgs e)
- {
- Application.Exit();
- }
- private void label3_Click(object sender, EventArgs e)
- {
- }
- private void textBox1_TextChanged(object sender, EventArgs e)
- {
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- private void buttonForm_Click_1(object sender, EventArgs e)
- {
- try
- {
- dataGridView1.RowCount = int.Parse(textBox1.Text);
- dataGridView1.ColumnCount = int.Parse(textBox2.Text);
- array = new int[dataGridView1.RowCount][];
- dataGridView1.Visible = true;
- buttonRez.Visible = true;
- for (int i = 0; i < dataGridView1.RowCount; i++)
- {
- array[i] = new int[dataGridView1.ColumnCount];
- for (int j = 0; j < dataGridView1.ColumnCount; j++)
- {
- if (i % 2 == 0) array[i][j] = 1;
- else array[i][j] = 0;
- }
- }
- for (int i = 0; i < dataGridView1.RowCount; ++i)
- for (int j = 0; j < dataGridView1.ColumnCount; ++j)
- dataGridView1.Rows[i].Cells[j].Value = array[i][j];
- dataGridView1.Show();
- buttonRez.Enabled = true;
- }
- catch (Exception exc)
- {
- MessageBox.Show(exc.Message);
- }
- }
- private void buttonRez_Click_1(object sender, EventArgs e)
- {
- try
- {
- dataGridView2.ColumnCount = 0;
- dataGridView2.RowCount = int.Parse(textBox1.Text);
- dataGridView2.ColumnCount = int.Parse(textBox1.Text);
- dataGridView2.Visible = true;
- for (int r = 0; r < dataGridView2.RowCount; ++r)
- for (int c = 0; c < dataGridView2.ColumnCount; ++c)
- if (c > r && array[r][c] == 0 || c < r && array[r][c] == 1)
- dataGridView2.Rows[r].Cells[c].Value = "";
- else
- dataGridView2.Rows[r].Cells[c].Value = array[r][c];
- dataGridView2.Show();
- buttonRez.Enabled = false;
- }
- catch (Exception exc)
- {
- MessageBox.Show(exc.Message);
- }
- }
- }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д