In the original code,
sim.Add(fare);
fare.Clear();
the list that was just added to sim is cleared, therefore the data are lost.
If you execute sim.Add(fare.ToList( )), a new list is created by ToList, which is a copy of fare; it is also added to sim. Therefore, fare.Clear does not clear the added list.
Two lists having the same data will exist for a short period of time. It is more efficient to do something like this:
for( int s = 0; s < sims; s++)
{
List<Chickens> fare= new List<Chickens>( );
for( int b = 0; b < sa; b++)
{
. . .
}
sim.Add( fare);
}
In this code:
List<Chickens> fare2 = new List<Chickens>();
fare2 = fare;
sim.Add(fare2)
fare.Clear();
a new empty list is created, but then fare2 is repointed to the list that is referenced by fare. The new list is lost. Both of fare2 and fare now represents the same list object, because fare2=fare does not create a copy of the list. Then fare.Clear deletes the data (similar to fare2.Clear). This is not suitable.
A: For loops are used outside of homework quite alot I am guessing. (This is not homework btw, I did this years ago, but there appears to be no way from what I have read now to choose in c# what is a value variable, and reference variable, otherwise this would have been completed much sooner. Also, if percieved as homework, maybe a link to the appropriate educational link will suffice.) Btw, this space is gigantic, it is inevitable that learning one useful framework will still require us to go back and touch on / relearn basics. Months can be spent not toucing on the above /certain aspects, even when you have foregone your entire life for this space.
B: There maybe other ways, If I had more experience I may be able to suggest them besides using 2 for loops. But i cannot see anything that would work better, or at least work at this stage. If you have any suggestions I would like to hear them, otherwise thanks for your non-useful comment.
Maybe you should change it to this: sim.Add(fare.ToList( )). Then you can clear the fare.
Or you can assign a new empty list to fare, instead of clearing.