I have two List and I want to set one of them to another:
var entities = new List<Entity>() { new Entity(), new Entity(), new Entity() };
List<Entity> newCollection = new List<Entity>();
I'm doing this using two ways:
1:
newCollection = entities;
2:
foreach (var entity in entities)
{
entity.OnDeleted += Entity_Deleted;
newCollection.Add(entity);
}
There are many ways, but I want to use foreach, because I want to subscribe to event of Entity class and then add it to collection.
I wanted to know is there any big difference between these ways?
Will I have performance problems when I use foreach?