Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to Enumerate a SortedList
Message
From
01/02/2009 04:45:50
 
 
To
31/01/2009 10:57:29
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01378599
Message ID:
01378651
Views:
6
>Thanks. But I figured it out. By CASTING the list to an IDictionary I was able to enumerate the list. What I was originally worried about was losing the link to the original list through the cast, thus losing the connection to the original controls. But the following cast worked fine, and I was able to enumerate the list.
>
>IDictionary EnumList = (IDictionary)oApp.db.DataControls;

Hi,
AFAICS you don't need to cast to IDictionary at all - see my suggestion.
But even if you did need to specifically reference DataControls as IDictionary you could just use.
foreach (Object o in DataControls as IDictionary<string,Control>){}
Don't worry about losing information - you're just looking at it in a more restricted way.

Regards,
Viv

>
>bob
>
>
>>>I have a sorted list defined as follows: (Note Less/Greater than sign = () )
>>>
>>>public SortedList(string, Contro) DataControls = new SortedList(string, Control)();
>>>
>>>I want to enumerate that list like this:
>>>
>>>foreach(SomeType DataCtrl in DataControls)
>>>
>>>{
>>> string cType = DataCtrl.Value.GetType().Name;
>>>
>>> switch (cType)
>>> {
>>> case "TextBox":
>>> //do Somthing
>>> break;
>>> case next...
>>> }
>>>}
>>>
>>>My problem is not knowing the the SomeType. I've tried the following defintion:
>>>
>>>public IDictionary DataControls = new SortedList(string, Control)();
>>>
>>>And then using the DictionaryEntry type, but then I lose some functionality of the SortedList that I need in other places in the code.
>>>
>>>Ideas are welcome...I just want to enumerate this list.
>>>
>>>Thanks.
>>>
>>>bob
>>
>>
>>Off the top of my head, you probably could use:
>>
>>for(Control sometype ...
>>
>>or
>>
>>for(Object sometype...
>>
>>
>>
>>John
Previous
Reply
Map
View

Click here to load this message in the networking platform