Structure of C#
using System;
// Gives access to Console and other basic features
namespace
MyFirstProgram
// Defines a namespace
{
class
Program
// Main class of the program
{
static
void
Main(
string[] args)
// Main method, starting point
{
Console.WriteLine(
"Hello, World!");
// Prints output to screen
}
}
}
-
using System;
using System;
This line allows your program to use
predefined classes and functions in the System namespace.
For example, Console.WriteLine()
is part of System
.
It's like importing built-in tools so you can
use them in your code.
A namespace is like a
container for your classes. It helps organize code and avoid naming conflicts
when your program gets bigger.
Think
of it like putting files in folders.
All C# code must be written inside a class.
Here, the class is named Program
.
A class is a blueprint that contains data (variables) and
actions (methods or functions).
It's like a box that holds your actual code
logic.
This is the entry point of
the C# program. When you run the program, execution starts from this method.
·
static
: You don’t need to create an object to run this
method.
·
void
: This means the method doesn’t return any value.
·
Main
: The name of the method where the program starts.
·
string[]
args
: This is used to take
command-line arguments (optional for now).
It tells the computer: "Start here!"
This line displays text on the screen.
·
Console
: A built-in class for input/output.
·
WriteLine()
: A method that prints the given text and moves to a
new line.
This is the actual action of
your program.
Comments
Post a Comment