我有一個C#類的人,我想總的小時數:C#for循環和做加法
Person Person1 = new Person();
Person1.Name = "Paul";
Person1.Age = 38;
Person1.actualGender = Person.Genders.male;
Person1.workedHours = 15.5f;
Person Person2 = new Person();
Person2.Name = "Frank";
Person2.Age = 15;
Person2.actualGender = Person.Genders.female;
Person2.workedHours = 5f;
我能做到這一點是這樣的:
float TotalHours;
TotalHours = Person1.workedHours + Person2.workedHours;
但如何我是否真的在foreach循環中執行,因爲我必須有2個以上的人。
我的類:
{
public string Name { get; set; }
public int Age { get; set; }
public enum Genders { male, female }
public Genders actualGender { get; set; }
public float workedHours { get; set;}
}
你應該學習使用數組fore'' –