I have a function defined like this:
public static void ShowAbout(Point location, bool stripSystemAssemblies = false, bool reflectionOnly = false)
This flags CA1026 “Replace method ‘ShowAbout’ with an overload that supplies all default arguments”. I can’t do Point location = new Point(0, 0) or Point location = Point.Empty because neither are compile time constants and therefore cannot be the default values for that function argument. So the question is, how does one go about specifying default argument values for structures? If it can’t be done, likely I’ll go for suppressing CA1026 in source with whatever justification someone here gives.
You can do this:
From the C# 4 spec, section 10.6.1:
So you could also use:
EDIT: If you wanted to default to a value other than the point (0, 0), it’s worth knowing about another trick:
This would also let callers explicitly say, “you pick the default” by passing in null.