A method or function may have a list of parameters. That's the part between the parentheses after the method's name:
void FunctionName( /* parameters here */ )
{
}
A parameter always looks like this:
Type name
Where Type
is the type of the value, and name
is any legal identifier you want. If you want multiple parameters, separate them with comma's:
void MethodName(Type1 name1, Type2 name2)
{
}
Also note the void
before the method name. This indicates that the method is expected to return no value. if you want your function to return a value, simply replace void
by the type of value you want it to return.
In your case, Dictionary<string, string>
is the type, and the name could be, for example, someDictionary
. Note that it doesn't have to be myDictionary
, but it can be.
static public void PrintDictionary(Dictionary<string, string> someDictionary)
{
// print someDictionary from here
}
And then you call it like you did:
PrintDictionary(myDictionary);
The rest of your code is correct. You'll only have to find out how to print your dictionary. For example:
static public void PrintDictionary(Dictionary<string, string> someDictionary)
{
foreach(KeyValuePair<string, string> pair in someDictionary)
{
Console.Write(pair.Key);
Console.Write(" => ");
Console.WriteLine(pair.Value);
}
}
Note that I changed the name function2
to PrintDictionary
in my examples. A method or function name should be a meaningful name, and the C# convention is to start it with an upper-case letter.