26 - İki Boyutlu Dizi Örneği : Seçimli Oyun

 

2 bölüm için 3 durum kaydedecek bir dizi oluşturalım.


  public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

        string[,] oyun = new string[2, 3];

        int index = 0;

        private void button1_Click(object sender, EventArgs e)

        {

            oyun[index, 0] = comboBox2.SelectedItem.ToString();

            oyun[index, 1] = comboBox3.SelectedItem.ToString();

            oyun[index, 2] = comboBox4.SelectedItem.ToString();

            index++;

        }

        int bolum = 1;

        private void button2_Click(object sender, EventArgs e)

        {/*

            foreach (var item in oyun)

            {   

                listBox1.Items.Add(item);

            }          */


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

            {

                listBox1.Items.Add("Bölüm "+bolum);

                for (int j = 0; j < 3; j++)

                {

                    listBox1.Items.Add(oyun[i, j]);

                }

                bolum++;

            }

            

        }

Yorumlar

Bu blogdaki popüler yayınlar

14 - Dizi Oluşturma, Değer Atama

12 - Bir Boyutlu Diziler - Çalışma Soruları

27 - Koleksiyonlar: ArrayList()