2011-08-08 7 views
0

私はベクトル2の二つのリストがあります:位置と床を、私はこれをやろうとしています。ここでリストから他のオブジェクトと同じ値を持つすべてのオブジェクトを他のリストから削除します。位置は、リストから位置を削除床と同じ場合 :XNA

は、私が仕事だろうと思ったものですが、それはしていません:私は、これは良い方法ではありませんので、どのように私ライトはそれができ

public void GenerateFloor() 
    { 

     //I didn't past all, the code add vectors to the floor List, etc. 
     block.Floor.Add(new Vector2(block.Texture.Width, block.Texture.Height) + RoomLocation); 

     // And here is the way I thought to delete the positions: 
     block.Positions.RemoveAll(FloorSafe); 
    } 

    private bool FloorSafe(Vector2 x) 
    { 
     foreach (Vector2 j in block.Floor) 
     { 
      return x == j; 
     } 

     //or 
     for (int n = 0; n < block.Floor.Count; n++) 
     { 
      return x == block.Floor[n]; 
     } 

    } 

知っていますか? Floors Vector2のいずれかと同じ位置Vector2をすべて削除する必要があります。

============================================== =================== EDIT: それは動作します!それを行う方法を探して人々のために、ここでHexxagonalの答えの私の最終的なコードは次のとおりです。

public void FloorSafe() 
    { 
     //Gets all the Vectors that are not equal to the Positions List. 
     IEnumerable<Vector2> ReversedResult = block.Positions.Except(block.Floor); 

     //Gets all the Vectors that are not equal to the result.. 
     //(the ones that are equal to the Positions). 
     IEnumerable<Vector2> Result = block.Positions.Except(ReversedResult); 

     foreach (Vector2 Positions in Result.ToList()) 
     { 
      block.Positions.Remove(Positions); //Remove all the vectors from the List. 
     } 
    } 

答えて

2

あなたは除きLINQを行うことができます。これにより、FloorsコレクションにないPositionsコレクションのすべてが削除されます。

result = block.Positions.Except(block.Floor) 
+0

甘い、それは働きます!私は削除されていないいくつかのジャンクを持っていますが、私は残りの作業をする方法を見つけるでしょう! – Nairda

関連する問題