Set array key as string not int?

前端 未结 6 1036
耶瑟儿~
耶瑟儿~ 2020-12-03 06:58

I am trying to set the array keys as a strings like in the example below, but inC#.



        
6条回答
  •  情深已故
    2020-12-03 07:12

    Uhm I'm guessing you want a dictionary:

    using System.Collections.Generic;
    
    // ...
    
    var dict = new Dictionary();
    dict["key_name1"] = "value1";
    dict["key_name2"] = "value2";
    string aValue = dict["key_name1"];
    

提交回复
热议问题