If I have a function with an optional argument like so:
public string testFunction (string arg1 = "Adam"){
return "Hello " + arg1;
}
If I pass a null string to the function, will the function return:
"Hello Adam"
Or:
"Hello " (Hello null)
If I have a function with an optional argument like so:
public string testFunction (string arg1 = "Adam"){
return "Hello " + arg1;
}
If I pass a null string to the function, will the function return:
"Hello Adam"
Or:
"Hello " (Hello null)
This is quite simple to just try out with a simple C# console application.
The answer is that arg1
is null
, and the output is Hello
The way you have it currently setup, the default is "Adam", so you can call the function like so; string mystring = testfunction();
and it will return "Hello Adam", anything you pass in, will replace Adam, including null.