Reputation: 11
I have these 3 lists.
public List<Rectangle> CoTree;
public List<Rectangle> CoRock;
public List<Rectangle> PlayerBlock = new List<Rectangle>();
In the update method I want to change all the elements in both lists(CoTree
and CoRock
) and to put both lists in PlayerBlock
lits so that it will change all the elements in PlayerBlock
.
CoTree=tree.HitBox.FindAll(item => item.Intersects(player.HitBox));
CoRock=rock.HitBox.FindAll(item => item.Intersects(player.HitBox));
// what I need is PlayerBlock = CoTree+CoRock;
Upvotes: 0
Views: 60
Reputation: 52528
I don't know if an item can occur in both CoTree
and CoRock
. If it can, you should use Union
, to get a list in that contains every element only once:
PlayerBlock = CoTree.Union(CoRock).ToList();
You can use Concat
if it is no problem that an element occurs twice in PlayerBlock
:
PlayerBlock = CoTree.Concat(CoRock).ToList();
Upvotes: 2
Reputation: 918
You should use the Concat
method.
You should use CoTree.Concat(CoRock)
and then ToList()
to convert to a List
Upvotes: 0