Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two-dimensional array with .Add in C#

Tags:

c#

collections

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?

like image 663
Maxim V. Pavlov Avatar asked Jun 05 '26 22:06

Maxim V. Pavlov


1 Answers

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.

like image 60
Vladislav Zorov Avatar answered Jun 07 '26 10:06

Vladislav Zorov