how to get single item in foreach loop ??
-
how to get single item in foreach loop ?? here is the sample foreach (clsLabels lbl in m_clsLabelCollection) { lstlblname.Items.Add(lbl.label); lstlblvalue.Items.Add(lbl.Value); lstcustext.Items.Add(lbl.customValue); } i want a perticular lable from the clsLabelCollection(collection class inherited from CollectionBase) class clsLabels constructor added to clsLabelCollectionclass clsLabels(string,string,string)
sikandar
-
how to get single item in foreach loop ?? here is the sample foreach (clsLabels lbl in m_clsLabelCollection) { lstlblname.Items.Add(lbl.label); lstlblvalue.Items.Add(lbl.Value); lstcustext.Items.Add(lbl.customValue); } i want a perticular lable from the clsLabelCollection(collection class inherited from CollectionBase) class clsLabels constructor added to clsLabelCollectionclass clsLabels(string,string,string)
sikandar
-
actually clscollection class contain a list of labels and i want if a perticualr label name equals"name" which is exists in the collection class. how can i extract it. thanks for reply
sikandar
-
actually clscollection class contain a list of labels and i want if a perticualr label name equals"name" which is exists in the collection class. how can i extract it. thanks for reply
sikandar
-
Hello, Got it now! foreach(Label l in clscollection) { if(l.Name == "yourename") { //thats it } } All the best, Martin -- modified at 4:17 Friday 25th August, 2006
hi no not in that way i mean is there any other way loop mean continous searching i want to save time i do not want to compare just assign of perticular. if possible thanks.
sikandar
-
hi no not in that way i mean is there any other way loop mean continous searching i want to save time i do not want to compare just assign of perticular. if possible thanks.
sikandar
-
how to get single item in foreach loop ?? here is the sample foreach (clsLabels lbl in m_clsLabelCollection) { lstlblname.Items.Add(lbl.label); lstlblvalue.Items.Add(lbl.Value); lstcustext.Items.Add(lbl.customValue); } i want a perticular lable from the clsLabelCollection(collection class inherited from CollectionBase) class clsLabels constructor added to clsLabelCollectionclass clsLabels(string,string,string)
sikandar
-
how to get single item in foreach loop ?? here is the sample foreach (clsLabels lbl in m_clsLabelCollection) { lstlblname.Items.Add(lbl.label); lstlblvalue.Items.Add(lbl.Value); lstcustext.Items.Add(lbl.customValue); } i want a perticular lable from the clsLabelCollection(collection class inherited from CollectionBase) class clsLabels constructor added to clsLabelCollectionclass clsLabels(string,string,string)
sikandar
Double up the collection. Often I will use both a list and a hash in 1.1. I use the list for iteration and the hash for indexing. If the data is good enough I will keep it in an Array List sorted and Binary Search it.
On two occasions I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question. - Charles Babbage
-
how to get single item in foreach loop ?? here is the sample foreach (clsLabels lbl in m_clsLabelCollection) { lstlblname.Items.Add(lbl.label); lstlblvalue.Items.Add(lbl.Value); lstcustext.Items.Add(lbl.customValue); } i want a perticular lable from the clsLabelCollection(collection class inherited from CollectionBase) class clsLabels constructor added to clsLabelCollectionclass clsLabels(string,string,string)
sikandar
Since you mentioned that clsLabelCollection inherits from CollectionBase, it should have a Contains and an IndexOf method. Assuming that both of these are actually implemented in the collection class, you can use them to find a specific clsLabels instance: clsLabels l = null; if (m_clsLabelCollection.Contains("value")) { int i = m_clsLabelCollection.IndexOf("value"); l = m_clsLabelCollection[i]; } You can also iterate over the collection (using foreach) and explicitly test to see if the current item is equal to the one you want. When you find the match, break out of the loop. This would be something like this: clsLabels l = null; foreach(clsLabels lbl in m_clsLabelCollection) { if (lbl.label == "value") { l = lbl; break; } } I'm assuming that lbl.label is a string field and that you are looking for the label "value".