Search code examples
c#usability

What is the most inuitive way to ask for objects in pairs?


So I have to design a class that works on a collection of paired objects. There is a one-to-one mapping between objects. I expect the client of the class to have established this mapping before using my class.

My question is what is the best way to allow the user of my class to give me that information?

Is it to ask for a collection of pairs like this?

MyClass(IEnumerable<KeyValuePair<Object, Object>> objects)

Or seperate collections like this?

MyClass(IEnumberable<Object> x, IEnumerable<Object> y)

Or is there another option?

I like the first because the relationship is explicit, I don't like it because of the extra work it puts on the client.

I like the second because the types are more primitive and require less work, I don't like it because the mapping is not explicit. I have to assume the order is correct.

Opinions please?


Solution

  • In .NET 4 you should be using Tuple<T1,T2>. More info on the Tuple class at MSDN.