|
|
FYI:
-
The source code for a C# program is stored in one or more text files with
a file extension of
.cs , as in
test .cs .
-
Using the command-line compiler provided with Visual Studio or the Net
Frame Work, the codes in a program can be compiled with the command line
directive
- "system" directive: references a namespace called
System that is provided by
the Microsoft .NET Framework class library.
- The system namespace contains the
Console class referred to
in the
Main method.
- The
Main method has a
static modifier, is the
main entry point for a program—the method that is called to begin
execution—is always a static method named
Main .
|
|
//It is a Namespace that you need to compile C#
using System;
//everything should be under a class
class test
{
// public variable declaration area
// Main out-put function that will execute to display the result
public static void Main()
{
//out put inside a command window
Console.WriteLine("Welcome to Hello world");
Console.Write("What is your name?: ");
//read input from the commandline
string str = Console.ReadLine();
Console.WriteLine("Hello: " + str);
}
}
|
|
Let us do some mistake to under the flow. |
|
|
No Entry Point: Must have an entry point
//It is a Namepsace that you need to compile C#
//this will not compile
//test_with_noentry.cs
using System;
//everyting should be under a class
class test
{
// public variable declaration area
// Main out-put function that will execute to display the result
//public static void Main()
void Main()
{
//out put inside a command window
Console.WriteLine("Welcome to Hello world");
Console.Write("What is your name?: ");
//read input from the commandline
string str = Console.ReadLine();
Console.WriteLine("Hello: " + str);
}
}
|
Must have a return data type
//It is a Namepsace that you need to compile C#
//this will not compile
//test_with_novoid.cs
using System;
//everyting should be under a class
class test
{
// public variable declaration area
// Main out-put function that will exucute to display the result
public static Main()
{
//out put inside a command window
Console.WriteLine("Welcome to Hello world");
Console.Write("What is your name?: ");
//read input from the commandline
string str = Console.ReadLine();
Console.WriteLine("Hello: " + str);
}
} |
|
|
|
|