Our first program is listed below:
class Program
{
static void Main(string[] args)
{
int i = 0;
int j = 2;
System.Console.WriteLine("i=" + i);
System.Console.WriteLine("j=" + j);
}
}
The heart of the program has four lines of code:
int i = 0;
int j = 2;
System.Console.WriteLine("i=" + i);
System.Console.WriteLine("j=" + j);
It defines two variables, assigns the values and output the content of the variables.
A function groups a series of statements. The following code defines a function.
static void Main(string[] args)
We can rewrite the program as follows:
using System; // Here is the change
class Program
{
static void Main(string[] args)
{
int i = 0;
int j = 2;
Console.WriteLine("i=" + i);
Console.WriteLine("j=" + j);
}
}
The program starts with a using
directive that references the System
namespace.
Namespaces provide a hierarchical means of organizing C# programs and libraries.
After importing the namespace we don't need to reference the Console
class with its full qualified name.
The Main
method is declared with the static
modifier.
By convention, a static method named Main
serves as the entry point of a program.
java2s.com | Contact Us | Privacy Policy |
Copyright 2009 - 12 Demo Source and Support. All rights reserved. |
All other trademarks are property of their respective owners. |