Generic.List

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

Hello,

I have a Generic.List(Of MyClass)

MyClass has two properties: ID and Value, both strings.

I want to look for the item, in my Generic.List(Of MyClass), with a
given ID.

How can I do this?

Thanks,

Miguel
 
shapper said:
Hello,

I have a Generic.List(Of MyClass)

MyClass has two properties: ID and Value, both strings.

I want to look for the item, in my Generic.List(Of MyClass), with a
given ID.

How can I do this?

By looping through the list and looking for the id.

If you would use a Dictionary<sring, MyClass> instead, and using the ID
as key, you would be able to get the item directly.
 
Hello there
By looping through the list and looking for the id.
Its also possible to implement a class that derives from List<MyClass> and
implement a ContainsKey method.
In this method, you can use the Enumerator to loop through the data
If you would use a Dictionary<sring, MyClass> instead, and using the ID as
key, you would be able to get the item directly.
Yes, that would be the prefered way :-)
 
Back
Top