0

I have a function defined like this:

public void Foo(string arg1="defaultvalueForArg1", string arg2="defaultvalueForArg2")
{
    ...
}

Now i want to call this function and provide a special value for arg2:

Foo("defaultvalueForArg1", "specialValueForArg2");

This works. But i must copy and paste and explicitly specify the value for arg1 and i think this is not very clean. For example if the default-value for arg1 changes I must search for every place where i probably want to update the value for arg1 to use the new default-value. Is there a syntax or option to use simply the default-value provided for arg1 specified in Foo? Something like Foo(_, "specialValueForArg2"); (using _ which you probably known as discards). I can probably overload Foo but my question is if there is a real "buildin-function" for this issue in C#.

anion
  • 1,516
  • 1
  • 21
  • 35

0 Answers0