MicroSoft Visual Studio 2010 のコンソール プログラムに C# を使用して、皆さんの助けを借りてこれにいくつかの変更を加えましたが、このコンソール プログラムは正しく実行されています。ただし、main メソッドの出力セクションに「To Obey the Girl Scout Law」というモットーを表示する定数静的フィールドを実装する必要があります。それは簡単なものでなければならないことはわかっていますので、ご容赦ください。public static const string Motto = "To Obey the Girl Scout Law" をベース クラスに含めると、エラー メッセージが表示されます - The constant 'DemoScouts.GirlScout.Motto' can't be static. 以下は、このプロジェクトの完全なコードです。
パブリック クラス ガールスカウト {
public static const string Motto = "To Obey the Girl Scout Law";
public static string scoutName;
public static string enterName()
{
return scoutName;
}
public static int duesOwed;
public static int enterAmount()
{
return duesOwed;
}
public static int troopNumber;
public static int enterNumber()
{
return troopNumber;
}
}
class MainClass : GirlScout
{
static void Main()
{
Console.WriteLine();
Console.Write("Enter the Girl Scout's name: ");
GirlScout.scoutName = Console.ReadLine();
Console.WriteLine();
Console.Write("Enter their Troop Number: ");
string n = Console.ReadLine();
GirlScout.troopNumber = Int32.Parse(n);
GirlScout.enterNumber();
Console.WriteLine();
Console.Write("Enter the amount they Owe in Dues: $");
string d = Console.ReadLine();
GirlScout.duesOwed = Int32.Parse(d);
GirlScout.enterAmount();
Console.WriteLine();
// Seperate the input from the output:
Console.WriteLine();
Console.WriteLine(GirlScout.Motto);
Console.WriteLine("-----------------------------------------------");
Console.WriteLine();
// Display the new information:
Console.WriteLine("The name of the Girl Scout is: {0}", GirlScout.scoutName);
Console.WriteLine("The troop Number of the Girl Scout is: {0}", GirlScout.troopNumber);
Console.WriteLine("The amount of Dues Owed by this Girl Scout is: {0}", GirlScout.duesOwed);
// Keep the console window open in debug mode.
Console.ReadKey();
}
}
}
あらゆるアドバイスをいただければ幸いです。