For example:
Dictionary<string, Abstract> index = list.ToDictionary( a => a.ID );
The ID and objects in the list must be unique.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Trying to index a list of type abstract class via a member of the class. I'm sure there's examples of this out there but I cannot find them searching the web. How could I say index the list via the abstract class member string ID?
Thanks!
public class Abstract
{
public string ID;
public int value;
public int tolerance;
...
}
// I create a list
List<Abstract> list = new List<Abstract>();
// Add several instances to the list
Abstract instance = new Abstract();
list.Add(instance);
...
...
// Now I want to index the list via ID number string. How can I do this?
For example:
Dictionary<string, Abstract> index = list.ToDictionary( a => a.ID );
The ID and objects in the list must be unique.