My Main problem is : if i add "N" group to company and check it in the last , i see all of "Man"s arrange into all of groups like together ?
i this my problem is in the definition of class or references .
This is my code :
public class Man
{
public int Code { get; set; }
public string Name { get; set; }
public int Priority { get; set; }
public int Stoptime { get; set; }
public Boolean Lunch { get; set; }
public DateTime Arrival { get; set; }
public DateTime Departure { get; set; }
public int LunchTime { get; set; }
}
public class Group
{
public List<Man> People { get; set; }
public double Speed { get; set; }
public double Rate { get; set; }
public double Surcharge { get; set; }
public double TotalRate { get; set; }
}
public class Company
{
public List<Group> Groups { get; set; }
public Group BestGroup { get; set; }
public double Rate { get; set; }
public double Surcharge { get; set; }
public double FullRate { get; set; }
}
private List<Man> ShufflePosts(List<Man> ShufflePeoples)
{
List<Man> Temp = ShufflePeoples;
List<Man> Commixed = new List<Man>();
Random rand = new Random();
do
{
int shf = rand.Next(0, Temp.Count);
Commixed.Add(Temp[shf]);
Temp.RemoveAt(shf);
} while (Temp.Count > 1);
Commixed.Add(Temp[0]);
return Commixed;
}
public void CAStart(List<Man> Peoples)
{
var _Race = new Company();
_Race.Groups = new List<Group>();
for (int i = 0; i < 5; i++)
{
var Gr = new Group();
Gr.People = ShufflePosts(Peoples);
_Race.Groups.Add(Gr);
}
}
In the code Commixed.Add(Temp[0]);
VS show me error index out of range.
I check the variable and see below data:
ShufflePeoples.Count = 0, Temp.Count = 0, Commixed.Count = 1
Why this happens ? Where is my problem ?