How do I get previous key from SortedDictionary?

后端 未结 7 2232
误落风尘
误落风尘 2020-12-18 20:46

I have dictionary containing key value pairs.

SortedDictionary dictionary=new SortedDictionary();
dictionary.Add(1,33);
diction         


        
7条回答
  •  梦毁少年i
    2020-12-18 21:05

    How about this? I havent tested it though, but should give something to start think in this direction. Hope it helps.

            int input = 4;
            List lKeys = dictionary.Keys.ToList();
            int reqIndex = lKeys.IndexOf(input) - 1;
            int reqAnswer = dictionary[reqIndex];
    

    test for other conditions like if (reqIndex != -1) etc..

提交回复
热议问题