An integer array as a key for Dictionary

前端 未结 3 1592
死守一世寂寞
死守一世寂寞 2020-11-28 13:20

I wish to have the dictionary which uses an array of integers as keys, and if the integer array has the same value (even different object instance), they will be treated as

3条回答
  •  失恋的感觉
    2020-11-28 14:22

    Maybe you should consider using a Tuple

    var myDictionary = new Dictionary, string>(); 
    myDictionary.Add(new Tuple(3, 3), "haha1"); 
    myDictionary.Add(new Tuple(5, 5), "haha2"); 
    

    According to MSDN , Tuple objects Equals method will use the values of the two Tuple objects

提交回复
热议问题