I can not understood why this code doesn't changing value from null(compiler even can't see that null instead of that Im reciving blank spots)
public string? ClubName
{
get => _clubname;
set
{
_clubname = value ?? "it";
}
}
CodePudding user response:
Your setter uses the null-coalescing operator ??
, which substitutes "it" should value
be null:
_clubname = value ?? "it";
So, you can never assign null to the property via the setter.
However, your property is backed by this private field:
_string clubname;
which the compiler initializes to null.
While you can never set null
, the code in your screenshot never assigns a value, so the initial value remains.