Here is a piece of code:
public class Schema
{
public Schema(List<CountryParticipantsStages> places)
{
Places = places.Select(participant =>(AbstractGeneralParticipants) new GeneralParticipants(participant)).ToList();
}
...
Order of element in source and result lists will be the same if source list is iterated in full. But if if 'Schema' constructor is called in the middle of any iteration then order of elements in 'Places' list will be shifted...
To avoid this I see the only way to use not a 'Select' method but a 'for' loop that will go from 0th element:
public class Schema
{
public Schema(List<CountryParticipantsStages> places)
{
Places = new List<AbstractGeneralParticipants>(places.Count);
for (int i = 0; i < places.Count; i++)
{
Places.Add(new GeneralParticipants(places[i]));
}
}
The 2nd function looks unpleasantly, but I don't see any better way for that. And also, ReSharper suggests me to replays 'for' loop with 'foreach'...
Please advise.
Thanks a lot.