-2

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)

Adam Nygate
  • 325
  • 3
  • 14

2 Answers2

2

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

foolmoron
  • 175
  • 1
  • 6
0

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.

Trent
  • 1,595
  • 15
  • 37