Operator ?? null coalescing in XNA 4 inside if statement
-
15-04-2021 - |
質問
How can I fix my code under this text?
//puncts = puncts ?? new List<Vector2>() { new Vector2(position.X, position.Y) };
if (Vector2.Distance(position, puncts[indexpunkt] = puncts[indexpunkt] ?? new Vector2(position.X, position.Y) ) < 1)
indexpunkt++;
Error:
Error 1 Operator '??' cannot be applied to operands of type 'Microsoft.Xna.Framework.Vector2' and 'Microsoft.Xna.Framework.Vector2'
I wish create new puncts if it is null and add first element to its list.
Can I use operator ??
and how can I use it in if
statement?
解決
Vector2
is a Struct
and therefore cannot be null, so coalescing operators don't apply.
所属していません StackOverflow