Note that there are some explanatory texts on larger screens.

plurals
  1. PORemove all the objects from a list that have the same value as any other Object from an other List. XNA
    primarykey
    data
    text
    <p>I have two Lists of vector2: Position and Floor and I'm trying to do this: if a Position is the same as a Floor then delete the position from the List.</p> <p>Here is what I thought would work but it doesn't:</p> <pre><code> 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 &lt; block.Floor.Count; n++) { return x == block.Floor[n]; } } </code></pre> <p>I know this is not the good way, so how can I wright it? I need to delete all the Positions Vector2 that are the same As any of the Floors Vector2.</p> <p>=============================================================================== EDIT: It works! For people searching how to do it, here is my final code of the answer of Hexxagonal:</p> <pre><code>public void FloorSafe() { //Gets all the Vectors that are not equal to the Positions List. IEnumerable&lt;Vector2&gt; 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&lt;Vector2&gt; Result = block.Positions.Except(ReversedResult); foreach (Vector2 Positions in Result.ToList()) { block.Positions.Remove(Positions); //Remove all the vectors from the List. } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload