开发者

How to pass Dictionary<string, string> object in some method

开发者 https://www.devze.com 2023-02-05 17:19 出处:网络
Can somebody give an example 开发者_JAVA技巧of how i pass Dictionary object in some method.???You can pass a dictionary like a normal argument:

Can somebody give an example 开发者_JAVA技巧of how i pass Dictionary object in some method.???


You can pass a dictionary like a normal argument:

private void MyMethod(Dictionary<string,string> myDictionary) { 
    //code 
}

Or you can pass it as an object and cast later like:

private void MyMethod(Object myDictionary) { 
   string color = ((Dictionary<string,string>)myDictionary)["color"];
}


If from the syntax you are referring to .NET then it would be as simple as passing any other parameter into a method

AMethod(Dictionary<string,string> dictionary)
{
//  Stuff
}

If you are doing a new inside the AMethod to create a new dictionary then don't forget to add a "ref".

0

精彩评论

暂无评论...
验证码 换一张
取 消