Обработка динамических массивов - C#

Узнай цену своей работы

Формулировка задачи:

В общем, есть программа которая работает через массив static object[,] array;, нужно сделать чтобы она работала через int[][] A = new int[0][];

Решение задачи: «Обработка динамических массивов»

textual
Листинг программы
  1.     public partial class Form1 : Form
  2.     {
  3.         public Form1()
  4.         {
  5.             InitializeComponent();
  6.         }
  7.  
  8.         static int[][] array;
  9.  
  10.         private void label1_Click(object sender, EventArgs e)
  11.         {
  12.  
  13.         }
  14.  
  15.         private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
  16.         {
  17.  
  18.         }
  19.  
  20.         private void label2_Click(object sender, EventArgs e)
  21.         {
  22.  
  23.         }
  24.  
  25.         private void button3_Click(object sender, EventArgs e)
  26.         {
  27.             Application.Exit();
  28.         }
  29.  
  30.         private void label3_Click(object sender, EventArgs e)
  31.         {
  32.  
  33.         }
  34.  
  35.         private void textBox1_TextChanged(object sender, EventArgs e)
  36.         {
  37.  
  38.         }
  39.  
  40.         private void Form1_Load(object sender, EventArgs e)
  41.         {
  42.  
  43.         }
  44.  
  45.         private void buttonForm_Click_1(object sender, EventArgs e)
  46.         {
  47.             try
  48.             {
  49.                 dataGridView1.RowCount = int.Parse(textBox1.Text);
  50.                 dataGridView1.ColumnCount = int.Parse(textBox2.Text);
  51.  
  52.                 array = new int[dataGridView1.RowCount][];
  53.  
  54.                 dataGridView1.Visible = true;
  55.                 buttonRez.Visible = true;
  56.  
  57.                 for (int i = 0; i < dataGridView1.RowCount; i++)
  58.                 {
  59.                     array[i] = new int[dataGridView1.ColumnCount];
  60.                     for (int j = 0; j < dataGridView1.ColumnCount; j++)
  61.                     {
  62.                         if (i % 2 == 0) array[i][j] = 1;
  63.                         else array[i][j] = 0;
  64.                     }
  65.                 }
  66.                 for (int i = 0; i < dataGridView1.RowCount; ++i)
  67.                     for (int j = 0; j < dataGridView1.ColumnCount; ++j)
  68.                         dataGridView1.Rows[i].Cells[j].Value = array[i][j];
  69.                 dataGridView1.Show();
  70.                 buttonRez.Enabled = true;
  71.             }
  72.             catch (Exception exc)
  73.             {
  74.                 MessageBox.Show(exc.Message);
  75.             }
  76.         }
  77.  
  78.         private void buttonRez_Click_1(object sender, EventArgs e)
  79.         {
  80.             try
  81.             {
  82.                 dataGridView2.ColumnCount = 0;
  83.  
  84.                 dataGridView2.RowCount = int.Parse(textBox1.Text);
  85.                 dataGridView2.ColumnCount = int.Parse(textBox1.Text);
  86.  
  87.                 dataGridView2.Visible = true;
  88.                 for (int r = 0; r < dataGridView2.RowCount; ++r)
  89.                     for (int c = 0; c < dataGridView2.ColumnCount; ++c)
  90.                         if (c > r && array[r][c] == 0 || c < r && array[r][c] == 1)
  91.                             dataGridView2.Rows[r].Cells[c].Value = "";
  92.                         else
  93.                             dataGridView2.Rows[r].Cells[c].Value = array[r][c];
  94.  
  95.                 dataGridView2.Show();
  96.                 buttonRez.Enabled = false;
  97.             }
  98.             catch (Exception exc)
  99.             {
  100.                 MessageBox.Show(exc.Message);
  101.             }
  102.         }
  103.     }

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

12   голосов , оценка 3.833 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут
Похожие ответы