Hashtable with MultiDimensional Key in C#

后端 未结 16 1541
闹比i
闹比i 2020-11-27 02:58

I\'m basically looking for a way to access a hashtable value using a two-dimensional typed key in c#.

Eventually I would be able to do something like this



        
16条回答
  •  情书的邮戳
    2020-11-27 03:46

    Just in case anyone is here recently, an example of how to do this the quick and dirty way in .Net 4.0, as described by one of the commenters.

    class Program
    {
      static void Main(string[] args)
      {
         var twoDic = new Dictionary, String>();
         twoDic.Add(new Tuple(3, true), "3 and true." );
         twoDic.Add(new Tuple(4, true), "4 and true." );
         twoDic.Add(new Tuple(3, false), "3 and false.");
    
         // Will throw exception. Item with the same key already exists.
         // twoDic.Add(new Tuple(3, true), "3 and true." );
    
         Console.WriteLine(twoDic[new Tuple(3,false)]);
         Console.WriteLine(twoDic[new Tuple(4,true)]);
         // Outputs "3 and false." and "4 and true."
      }
    }
    

提交回复
热议问题