Skip to content
Discussion options

You must be logged in to vote

Hello.

Nullable<int> (known as int?) and int aren't a same type, so here a.C you can't use null-forgiving operator ! to declare the not-null state on the property C because you may change the result value from an int? to an int. The only way to get the inner value is int value = a.C!.Value, or also you can use pattern matching: if (a.C is { } value) ....

However, string? and string is a same type with different nullability, so a.B! means the value of the property B is not-null. Therefore the operator can be used on this case.

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@jnm2
Comment options

jnm2 Sep 18, 2021
Collaborator

@kyoyama-kazusa
Comment options

Answer selected by AliRezaBeigy
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