Skip to content
Discussion options

You must be logged in to vote

Due to null short-circuiting this behavior is expected. If tokens[2].mathContext is null, then Calculate is not executed so your cthird remains unassigned. You even highlighted CS0165, which explains the issue.

But since you already initialized third2 there is no need to introduce another variable in the out parameter and then assign it to third2:

// This causes CS0165 because cthird will not be assigned if mathContext is null:
//Token third2 = Token.Invalid;
//tokens[2].mathContext?.Calculate(out Token cthird);
//third2 = cthird; // issue: cthird might be uninitialized here

// But you can simply do this:
Token third2 = Token.Invalid;
tokens[2].mathContext?.Calculate(out third2); // thir…

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@jklw10
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@jklw10
Comment options

Answer selected by jklw10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants