I'm guessing you are using a Collection
of KeyValuePair<long, long>
and that these two values are the x and y coordinates. For settings only value, I would recommend setting the other value to -1
. This would be fine as you are not using ulong
.
Say these assumptions are correct and your collection is called Points
.
I would recommend using linq
where y is your desired value:
Points.Select(p => p.Value).ToArray();
or
Points.Select(p => p.Value).ToList();
This will return a new array or list, depending, containing all of the y values. If you needed the x values you would use Key
instead of Value
. As you are only grabbing the value, it doesn't matter if the Key
(x) is null, -1 or whatever.
Taking this a step further, you could select all of the y values, where x meets a condition. I'm guessing this would be useful to you based on your saying
only one axes values (y) for some points
Again, where Points
is the collection of KeyValuePair<long, long>
int example = 5;
Points.Where(p => p.Key == example).Select(p => p.Value).ToArray();
or
Points.Where(p => p.Key != -1).Select(p => p.Value).ToArray();
Continuation(See first comment):
Queue<KeyValuePair<long, long>> queue = new Queue<KeyValuePair<long, long>>();
KeyValuePair<string, Queue<KeyValuePair<long, long>>> pair = new KeyValuePair<string, Queue<KeyValuePair<long, long>>>("test", queue);
pair.Value.Enqueue(new KeyValuePair<long, long>(-1, 5));
I get no problem with this code, works fine.
Possible other solution:
Instead of having a KeyValuePair<long,long>
. You could have KeyValuePair<long,long[]>
. The long[]
would store one or two values based on your need. The only limitation would be that you would have to assume that if the array is of length one, then it is only storing y
and not x
, otherwise if the array is of size 2, then assume it is in an {x, y} format.