get dictionary value by key

前端 未结 10 1952
逝去的感伤
逝去的感伤 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:11

    That is not how the TryGetValue works. It returns true or false based on whether the key is found or not, and sets its out parameter to the corresponding value if the key is there.

    If you want to check if the key is there or not and do something when it's missing, you need something like this:

    bool hasValue = Data_Array.TryGetValue("XML_File", out value);
    if (hasValue) {
        xmlfile = value;
    } else {
        // do something when the value is not there
    }
    

提交回复
热议问题