Best collection to use with type Double as key

后端 未结 4 766
你的背包
你的背包 2020-12-21 14:33

I have this object:

Public Cactus{
    Public Double key;
    Public String value;
}

I have about ~100 Cactus, which all have

4条回答
  •  北海茫月
    2020-12-21 15:15

    Using a double as a key in a dictionary is generally a really bad idea. You will run into all sorts of problems with representation errors where you think you stored 0.1 in the dictionary but actually you stored something very close to but not quite equal to 0.1.

    I'd suggest using another type (string?) if you need exact matches.

    If you don't want exact matches but just finding the closest value, consider something like a SortedList instead.

提交回复
热议问题