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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top