Arun Kurmi

Arun Kurmi

  • 1.9k
  • 106
  • 90.3k

Foreach loop in C#

Mar 6 2013 5:24 AM
hi friends,
I want to understand following code line by line......... 
private void button1_Click(object sender, EventArgs e)
        {
            label2.Text = "";
            label3.Text = "";
           


            foreach (object checkeditem in checkedListBox1.Items)
            //why we cannot use instead of above line : foreach(CheckedListBox checkeditem in checkedListBox1.Items)
            {
                string str = checkedListBox1.GetItemCheckState(checkedListBox1.Items.IndexOf(checkeditem)).ToString();
//meaning of this line
                if (str == "Checked")
               //why we used "Checked" .
                {
                    label2.Text = label2.Text + checkeditem.ToString() + "\n";
                }
                else
                {
                    label3.Text = label3.Text + checkeditem.ToString() + "\n";
                }
            }

thanks....

Answers (5)