現在、プログラムが各クラスのパラメーターをフォームに表示する必要があるという問題がありますが、階層の最下位のクラスは表示されません。例えば; 「3 輪の三輪車に乗るチャリティー サイクリスト No. 1 と 300 ポンドのスポンサー」を表示したいのですが、「3 輪の三輪車に乗るチャリティー サイクリスト No. 1」しか表示されません。
これが私のスポンサーシップクラスです:
class Sponsorship : CharityCyclists
{
private double fundsRaised;
public double FundsRaised
{
get { return fundsRaised; }
set { fundsRaised = value; }
}
public Sponsorship(String type, int number, String finished, int hours, int mins, int secs, string bicycle, int wheels, double fundsRaised) : base(type, number, finished, hours, mins, secs, bicycle, wheels, fundsRaised)
{
this.fundsRaised = fundsRaised;
}
public override string ToString()
{
return base.ToString() + " and sponsorship amount: " + fundsRaised;
}
}
これが私のCharityCyclistsクラスです:
class CharityCyclists : Cyclists
{
private string bicycle;
private int wheels;
public string Bicycle
{
get { return bicycle; }
set { bicycle = value; }
}
public int Wheels
{
get { return wheels; }
set { wheels = value; }
}
public CharityCyclists(string type, int number, string finished, int hours, int mins, int secs, string bicycle, int wheels, double fundsRaised) : base(type, number, finished, hours, mins, secs)
{
this.bicycle = bicycle;
this.wheels = wheels;
}
public override string ToString()
{
return base.ToString() + " riding a " + bicycle + " with " + wheels + " wheels";
}
}
そして私のサイクリストクラス:
public static int NumFinished
{
get { return Cyclists.numFinished; }
set { Cyclists.numFinished = value; }
}
public string Type
{
get { return type; }
set { type = value; }
}
public int Number
{
get { return number; }
set { number = value; }
}
public string Finished
{
get { return finished; }
set { finished = value; }
}
public int Hours
{
get { return hours; }
set { hours = value; }
}
public int Mins
{
get { return mins; }
set { mins = value; }
}
public int Secs
{
get { return secs; }
set { secs = value; }
}
public Cyclists(string type, int number, string finished, int hours, int mins, int secs)
{
this.type = type;
this.number = number;
this.finished = finished;
this.hours = hours;
this.mins = mins;
this.secs = secs;
}
public override string ToString()
{
return type + " No. " + number;
}
public Cyclists()
{
}
これは、フォームのリストボックスに追加される場所です。
Cyclists[] cyclistsList;
cyclistsList = new Cyclists[2];
cyclistsList[0] = new CharityCyclists("Novelty Charity Cyclist", 1, "Not Finished", 0, 0, 0, "Tricycle", 2, 300);
cyclistsList[1] = new CompetitiveCyclists("Competitive Cyclist", 1, "Not Finished", 0, 0, 0, 25, 2);
for (int i = 0; i < MAX_CYCLISTS; i++)
{
lstCyclists.Items.Add(cyclistsList[i]);
}
ありがとう!