James
James

Reputation: 2871

Data type for storing object pair other than Dictionary in C#

What would be the best data type for storing non-unique pairs of objects? I cannot use Dictionary because the key has to be unique. I could create an object with the two data types as properties and store them in a list, but that wouldn't be flexible enough to accommodate the different data type pairs. Something almost like Dictionary but non-unique. A build-in solution from .NET would be even better.

Upvotes: 3

Views: 2264

Answers (2)

Sidharth Mudgal
Sidharth Mudgal

Reputation: 4264

You could use List<KeyValuePair<T1,T2>>. Dictionary class uses KeyValuePair too.

Upvotes: 2

Jonathon Reinhart
Jonathon Reinhart

Reputation: 137398

I think a List<Tuple<T1,T2>> would work best here.

Upvotes: 7

Related Questions