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
VulpesPosted Mar 6, 2013, 7:17 AM
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.
Arun KurmiPosted Mar 6, 2013, 6:39 AM
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???
VulpesPosted Mar 6, 2013, 6:32 AM
http://www.c-sharpcorner.com/Members/?Type=legend
Santosh YadavPosted Mar 6, 2013, 6:00 AM
VulpesPosted Mar 6, 2013, 5:44 AM