Reputation: 11
Hi i want to call a method:
public string MyMethod($MyVariable)
{
}
Where the variable $MyVariable contains all arguments for the function i.e.:
$MyVariable = "argument1,argument2,argumentn"
Is this possible, do i Need Special Syntax?
Upvotes: 0
Views: 834
Reputation: 8194
I can't tell if you want to pass one string containing all parameters, or multiple parameters.
Single parameter
public void Main()
{
MyMethod("argument1, argument2, ...");
}
public string MyMethod(string parameters)
{
Console.Write(parameters);
return "whatever your string was";
}
Output:
argument1, argument2, ...
Multiple parameters
public void Main()
{
MyMethod("argument1", "argument2", "...");
}
public string MyMethod(params string[] parameters)
{
foreach (var parameter in parameters)
{
Console.Write(parameter);
}
return "whatever your string was";
}
Output:
argument1
argument2
...
Upvotes: 2