2012-01-12 74 views
0

内XNA 4空合并如何修复我的代码在此文本下?运营商?如果在语句

//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 1 Operator '??' cannot be applied to operands of type 'Microsoft.Xna.Framework.Vector2' and 'Microsoft.Xna.Framework.Vector2' 

我希望创造新的puncts如果是零和第一个元素添加到其列表中。 我可以使用运营商??以及我如何使用if声明?

回答

3

Vector2Struct,因此不能为空,所以合并运算符不适用。

+0

所以,我不能做任何if语句与我的vector2? – deadfish 2012-01-12 18:07:59

+0

你可以用vector2在if语句中做很多事情,你不能检查它是否为null。这就像说我一样; if(i == null){...} – 2012-01-12 18:17:57

+0

实际上它可能更像是说我int;如果(我==“你好”){...} – annonymously 2012-01-16 03:12:52