Reputation: 4019
I have a List
of IWord
objects named taggedInput
.
I need to associate each element with its own List
of IWord
objects.
For this I need to use a different datatype.
In this datatype, both the parent list and the child list must be dynamic, and must be populated at run-time.
The parent list must allow duplicate values (so it cannot be a Dictionary
object).
I intend to iterate through the parent list, and manipulate (add, remove, reorganize) the elements in the child list. Each element in both the parent and child lists must be accessible by its position in the list.
Here is an image I made to better illustrate what I need:
What is the best data type to use for this? I need something like List<IWord,List<IWord>>
(but that wouldn't be a list)
Upvotes: 0
Views: 303
Reputation: 70162
I am assuming you cannot change the IWord
interface? In that case I would use another type to allow you to form the required relationship ...
public class WordWithRelatives
{
public IWord Word {get;set;}
public List<IWord> Relatives {get;set;}
}
Then you simply require a list of the above
var taggedInput = List<WordWithRelatives>();
You could also make WordWithRelatives
implement IWord
by forwarding the IWord
interface methods to the Word
instance it contains.
Upvotes: 1