I would like to ask help how to implement a similar data structure as datatree.
I have a flatten list of custom class and would like to access items by pair of indices.
For instance item1 would have id 0 and 5.
Essentially a class that imolements Ienumerable, but instead of having indexing of integers, I would like to access items by pair of indices.
Or maybe more simple how can I extend a custom class with properties of Datatree?
menno
(Menno Deij - van Rijswijk)
#2
You can overload the index operator to take two indices:
class ItemCollection
{
public Item this[int i, int j]
{
get
{
// return item based on two indices
}
}
}
Or you can create a dictionary that takes a Tuple<int,int>
as key
var dict = new Dictionary<Tuple<int, int>, Item>();
Thanks it works nicely with indexing and tuples, I was trying to write public Item this[int i][int j]
, which did not work.