Hashtable with MultiDimensional Key in C#

后端 未结 16 1497
闹比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:29

    Look, this code works just fine:

        public Form1()
        {
                InitializeComponent();
        }
    
        private void Form1_Load(object sender, EventArgs e)
        {
    
            this.Services = new Dictionary();
            this.Services.Add("array1", new Hashtable());
    
            this.Services["array1"]["qwe"] = "123";
            this.Services["array1"][22] = 223;
    
            object zz = null;
            zz = this.Services["array1"]["qwe"];
            MessageBox.Show(zz.ToString()); // shows qwe
    
            zz = this.Services["array1"][22];
            MessageBox.Show(zz.ToString()); // shows 22
        }
    

    Now we just need a wrapper to avoid manually doing this.Services.Add("array1", new Hashtable());

提交回复
热议问题