Reputation: 10509
I need to store a collection of Point
pairs, but don't want to use plain C# arrays to be bound to use of iterators. Which is the easiest way (except using KeyValuePair<Point,Point>
) to have such an two dimensional collection at hand with being able to .Add(Point, Point)
to it?
Upvotes: 3
Views: 1650
Reputation: 3723
IEnumerable<Tuple<Point, Point>>
http://msdn.microsoft.com/en-us/library/dd268536.aspx
Upvotes: 1
Reputation: 3056
Point,Point
is not a key-value pair, it's a Tuple<Point,Point>
. You can create a List<Tuple<Point,Point>>
or whatever fits your needs.
However, you should keep something in mind - a Tuple
is an immutable structure - you can't change it's elements to point to other Point
objects (however, if the Point
object itself is mutable, you could mutate the Point
). If you need to be able to change elements from this list to point to other points, create your own class to hold these.
Upvotes: 4
Reputation: 9670
Subclass List<Tuple<Point,Point>>
and create an overload of .Add with two Point parameters.
public class MyCollection : List<Tuple<Point, Point>>
{
public void Add(Point p1, Point p2)
{
this.Add(Tuple.Create(p1, p2));
}
}
Upvotes: 4