How to pass a dictionary <string, string> object in some method

Can someone give an example of how I pass a Dictionary object in some method.

+4
source share
2 answers

You can pass the dictionary as a normal argument:

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

Or you can pass it as an object and do it later:

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

If you reference .NET from the syntax, then it would be as simple as passing any other parameter to the method

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

If you create a new one inside AMethod to create a new dictionary, be sure to add "ref".

+7
source

Source: https://habr.com/ru/post/1336119/


All Articles