Is is possible to obtain the position of a given KeyValuePair<,>
within a Dictionary<,>
, or the next object, without having an index
or alike?
For instance, assume that I have the following code:
Dictionary<Object, String>
dictionary = new Dictionary<Object, String>() {
{ new Object(), "String A" },
{ new Object(), "String B" },
{ new Object(), "String C" },
{ new Object(), "String D" },
{ new Object(), "String E" },
{ new Object(), "String F" },
};
String
knownValue = "String C";
From there, how should I procede to obtain the KeyValuePair<Object, String>
index or the KeyValuePair<Object, String>
with the "String D"
value?
UPDATE
A little bit of more info
In both the given example and where I'm trying to do this, both Keys
and Values
are unique. I'm using the Dictionary<,>
to keep track of two objects while knowing which one is associated to.
A little of more details, I'm using this Dictionary<,>
to keep track of a location and a Marker
on an Android app. I was requested to, after selecting a Marker
and popping out a little card with basic information about that location, enable swipping that card and show the next or previous location.
This is where this issue enters. I receive a list of locations from a server, which the order must be kept. After processing that list, I associate each location with a Marker
on the map.
At this moment, whenever the user clicks on a Marker
I use a LINQ expression to find that Marker
on the Dictionary<,>
and retrieve the associated location.