954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

why is there a semicolon in the body of methods but none at the end of method endings

// This is traditionally the first program written
using System;
namespace HelloWorldProgram
{
    class HelloWorld
    {
        static void Main()
        {
            Console.WriteLine("Hello World!");
        }
    }
}


I dont get why the statements in the body end with a " ; " but nothing is placed at the end of method headings. Guess this is the pain as a beginner in programming.....

Thanks Again !

techlawsam
Junior Poster in Training
56 posts since Aug 2011
Reputation Points: 10
Solved Threads: 0
 

{} indicates a block of code so the compiler knows that it ends when it reaches a closing }. ';' is used to mark the end of a statement so the compiler knows that you are done with that statement since C# ignores white space (except where significant). You could write

class
HelloWorld
{
static
void
Main()
{
Console.WriteLine(
"Hello World!"
)
;
}


As you get into more advanced programming, you'll find a few places where you have to type "};" :)

Momerath
Nearly a Senior Poster
3,384 posts since Aug 2010
Reputation Points: 1,232
Solved Threads: 558
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: