Reputation: 26919
For example I have four spreadsheets and I want to store something like this:
Rows 1,2,3 from spread1,
Rows 1,2 from spread2,
Rows 3,4 from spread3,
Row 3 from spread4
I thought I should use a Dictionary<> but MSDN says the Key Should be uniqe. so what is a correct way of doing this?
P.S: I am using .NET 3.5, cannot use Tuple. Thanks
Upvotes: 0
Views: 101
Reputation: 62514
Quick and straigtforward solution:
IDictionary<string, IList<int>> map = new Dictionary<string, IList<int>>
{
{ "spread1", new List<int> { 1, 2, 3 } },
{ "spread2", new List<int> { 1, 2 } },
{ "spread3", new List<int> { 3, 4 } },
{ "spread5", new List<int> { 3 } }
}
If you need some kind of flexibility - abstract spreads and related rows by a custom classes like suggested by others.
Upvotes: 1
Reputation: 164301
It sounds like a list of lists to me, List<List<T>>
. It would probably be nice to wrap it in a custom class to give you the semantics you want (if not, it can get complicated to remember what's in which list, etc; and perhaps you want some additional metadata on each sublist).
Upvotes: 1
Reputation: 838376
Make a custom class and use that as your key. Include all the fields you need to create a unique key (spreadsheet name and list of rows) then override Equals and GetHashCode appropriately.
Upvotes: 2