2012-01-12 39 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