Dictionary Implementation, but with custom class as key
I have implemented a dictionary like this code file
Now
Dictionary.Add(10, "Washington");
will work, but what if I want the key to be the latitude and longitude of the city?
can I pass my class as my key or do I need to adjust my dict
class ?6 Replies
If you make your
GeoLocation
class a struct
or a record
, pretty sure it will just work as the key
Since they use value equality
That way, no need to reimplement a Dictionary
so it would be something like this
No
hm this is for the
System.Collections.Generic
Dictionary
right? I am using my own dictionary implementation so if it is giving me Cannot apply indexing with [] to an expression of type 'Dict<GeoLocation, string>
does it mean I screwed-up in my implementation ?Yes, for the regular dictionary
I see no point implementing your own tbh
well it is for an exercise I am trying to solve
The focus of this exercise is the use of generics, and the understanding of interfaces and interface inheritance by implementing and using your own class(es).this is their reason for it so what am I supposed to do for it to work with my implementation using
struct
?