C# and Objects/Classes

Posted by user1192890 on Stack Overflow See other posts from Stack Overflow or by user1192890
Published on 2012-07-02T03:11:20Z Indexed on 2012/07/02 3:15 UTC
Read the original article Hit count: 198

Filed under:
|
|

I have tried to compile code from Deitel's C# 2010 for programmers. I copied it exactly out of the book, but it still can't find main, even though I declared it in one of the classes. Here is a look at the two classes:

For 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

Now for the GradeBook class:

 // 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

That is how I copied them. Here is how they appeared in the book:

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

and

 // 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

I don't see why they are not working. Right now I am using Visual Studio Pro 2010. Any Thoughts?

© Stack Overflow or respective owner

Related posts about c#

Related posts about oop