Hi i writing this below code for make some person. in query i want to get all persons and select instance form every person this below code is for Main method:
Persons[] person = { new Persons(534, "Komeil", "Shahmoradi", 20, 1.65f, 68.3f),
new Persons(1047, "Ahmad", "Darvishi", 18, 1.72f, 70) ,
new Persons(56, "Javad", "Amini", 28, 1.56f, 73.2f),
new Persons(2, "Hossein", "Kiany", 17, 1.80f, 65.6f) ,
new Persons(192, "Hossein", "Kazemy", 15, 1.80f, 83.6f),
new Persons(2002, "Hossein", "Saeedi", 43, 1.80f, 93.6f)};
Random rnd = new Random();
var QpersonsLocation = from value in person
select new Duty(rnd.Next(1,2000), value.pName, value.pFamily, value.pAge);
Console.WriteLine("[/] System seting location");
foreach (var item in QpersonsLocation)
{
Console.WriteLine(item.dId +"\t" + item.dName + "\t" + item.dFamily + "\t" + item.dAge + "\t" + item.dDuttyLocation+"\t");
}
And this is for my Persons class:
class Persons
{
public long pId { get; set; }
public string pName { get; set; }
public string pFamily { get; set; }
public byte pAge { get; set; }
public float pSize { get; set; }
public float pWeight { get; set; }
public Persons(long pId, string pName, string pFamily, byte pAge, float pSize, float pWeight)
{
this.pId = pId;
this.pName = pName;
this.pFamily = pFamily;
this.pAge = pAge;
this.pSize = pSize;
this.pWeight = pWeight;
}
}
problem in the lass code for Duty class :
class Duty
{
string[] locations = {"Esfahan",
"Tehran",
"Mashhad",
"Shiraz",
"Hamedan",
"Azarbayejan"};
public long dId {get;set;}
public string dName { get; set; }
public string dFamily { get; set; }
public byte dAge { get; set; }
public string dDuttyLocation { get; set; }
public Duty(long dId, string dName, string dFamily, byte dAge)
{
this.dId = dId;
this.dName = dName;
this.dFamily = dFamily;
this.dAge = dAge;
Random rnd = new Random();
int num = rnd.Next(0,locations.Length);
dDuttyLocation = locations[num];//problem
}
}
The code working correctly but the location not saving and always dDuttyLocation equals the last number of random number this below picture shows the result: