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....
Loading

VulpesRank #55 · 29.2K reputationPosted Mar 6, 2013, 2:17 AM EST
Broadly, an enumerable object is a collection which implements either IEnumerable or IEnumerable
In the case of the latter, T will be the type of the iteration variable.
In the case of the former, the type of the iteration variable will usually be object.
However, suppose you have an ArrayList which actually contains nothing but strings even though internally they're stored in an object[]. If you specify the type of the iteration variable to be string, then this will work because the runtime will attempt to cast each object in the collection to string and will only raise an exception if the cast is invalid.
VulpesRank #55 · 29.2K reputationPosted Mar 6, 2013, 12:44 AM EST
Santosh YadavRank #6,715 · 258 reputationPosted Mar 6, 2013, 1:00 AM EST
VulpesRank #55 · 29.2K reputationPosted Mar 6, 2013, 1:32 AM EST
http://www.c-sharpcorner.com/Members/?Type=legend
Arun Kurmi96 reputationPosted Mar 6, 2013, 1:39 AM EST
1 foreach(Control ctl in Controls)
2 foreach(FontFamily f in FontFamily.Families)
so i think syntax of foreach as:
foreach(1 2 3 4)
1 classname
2 create object of class
3 in keyword
4 collection that return value for our created object
**************************************
but i see another ex. as
foreach(KnownColor val in Enum.GetValues(typeof(KnownColor)))
here KnownColor is not a class so
what is syntax for foreach???