我曾尝试从 Deitel 的 C# 2010 为程序员编译代码。我将它完全从书中复制出来,但它仍然找不到 main,即使我在其中一个类中声明了它。下面看一下这两个类:
对于 GradeBookTest:
// Fig. 4.2: GradeBookTest.cs
// Create a GradeBook object and call its DisplayMessage method.
public class GradeBookTest
{
// Main method begins program execution
public static void Main(string[] args)
{
// create a GradeBook object and assign it to myGradeBook
GradeBook myGradeBook = new GradeBook();
// call myGradeBook's DisplayMessage method
myGradeBook.DisplayMessage();
} // end Main
} // end class GradeBookTest
现在对于 GradeBook 类:
// Fig. 4.1: GradeBook.cs
// Class declaration with one method.
using System;
public class GradeBook
{
// display a welcome message to the GradeBook user
public void DisplayMessage()
{
Console.WriteLine( "Welcome to the Grade Book!" );
} // end method DisplayMessage
} // end class GradeBook
我就是这样复制它们的。以下是它们在书中的出现方式:
1 // Fig. 4.2: GradeBookTest.cs
2 // Create a GradeBook object and call its DisplayMessage method.
3 public class GradeBookTest
4 {
5 // Main method begins program execution
6 public static void Main( string[] args )
7 {
8 // create a GradeBook object and assign it to myGradeBook
9 GradeBook myGradeBook = new GradeBook();
10
11 // call myGradeBook's DisplayMessage method
12 myGradeBook.DisplayMessage();
13 } // end Main
14 } // end class GradeBookTest
和
// Fig. 4.1: GradeBook.cs
// Class declaration with one method.
using System;
public class GradeBook
{
// display a welcome message to the GradeBook user
public void DisplayMessage()
{
Console.WriteLine( "Welcome to the Grade Book!" );
} // end method DisplayMessage
} // end class GradeBook
我不明白他们为什么不工作。现在我正在使用 Visual Studio Pro 2010。有什么想法吗?