-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clarify Optional Parameters and Nullable Optional Parameter Behavior in C#. #44408
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @shethaadit
The changes you've made emphasize the confusion rather than fixing it. A method signature can set the "default" value for an optional parameter. That's a different concept than the "default value" for a type. It also can be different than specifying a "missing" value. Consider this example:
public class Buffer<T>
{
private T[] _storage;
public Buffer(int size = 10)
{
_storage = new T[size];
}
}
The "default value" for size
is 10. That's different than the default value for the int
type (that's 0).
docs/csharp/programming-guide/classes-and-structs/named-and-optional-arguments.md
Outdated
Show resolved
Hide resolved
docs/csharp/programming-guide/classes-and-structs/named-and-optional-arguments.md
Outdated
Show resolved
Hide resolved
docs/csharp/programming-guide/classes-and-structs/named-and-optional-arguments.md
Outdated
Show resolved
Hide resolved
Hi @BillWagner, could you please check once if the updates makes sense? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again @shethaadit
This LGTM, and I'll now.
docs/csharp/programming-guide/classes-and-structs/named-and-optional-arguments.md
Outdated
Show resolved
Hide resolved
…tional-arguments.md
Summary
This PR improves the documentation for optional parameters in C# by:
T?
) parameters and optional parameters with default values.T? allTheOptionalMeanings = default
).Fixes #44404
Internal previews