Skip to content
Discussion options

You must be logged in to vote

You might need to chain if X was itself nullable, e.g.:

class A { public int? X }
string? s = a?.X?.ToString();

That basically expands into:

string? s;
if (a != null)
{
    int? temp = a.X;
    if (temp != null)
    {
        s = temp.Value.ToString();
    }
    else
    {
        s = null;
    }
}
else
{
    s = null;
}

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by MrTA2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants