get dictionary value by key

前端 未结 10 1927
逝去的感伤
逝去的感伤 2020-11-29 20:47

How can I get the dictionary value by key on function

my function code is this ( and the command what I try but didn\'t work ):

static void XML_Array         


        
10条回答
  •  春和景丽
    2020-11-29 21:10

    It's as simple as this:

    String xmlfile = Data_Array["XML_File"];
    

    Note that if the dictionary doesn't have a key that equals "XML_File", that code will throw an exception. If you want to check first, you can use TryGetValue like this:

    string xmlfile;
    if (!Data_Array.TryGetValue("XML_File", out xmlfile)) {
       // the key isn't in the dictionary.
       return; // or whatever you want to do
    }
    // xmlfile is now equal to the value
    

提交回复
热议问题