
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
What is the basic structure of a C# program?
Let us first see a sample program in C# −
using System; namespace DemoApplication { class HelloWorld { static void Main(string[] args) { Console.WriteLine("Welcome!"); Console.ReadKey(); } } }
Now let us see what all is included in the above program −
using
The first line of the program using System; - the using keyword is used to include the System namespace in the program. A program generally has multiple using statements.
Namespace Declaration
The next line has the namespace declaration. A namespace is a collection of classes. The DemoApplication namespace contains the class HelloWorld.
Class Declaration
The next line has a class declaration, the class HelloWorld contains the data and method definitions that your program uses. Classes generally contain multiple methods. Methods define the behavior of the class. However, the HelloWorld class has only one method Main.
Main Method
The next line defines the Main method, which is the entry point for all C# programs. The Main method states what the class does when executed.
Console.WriteLine
The Main method specifies its behavior with the statement Console.WriteLine("Welcome!");
WriteLine is a method of the Console class defined in the Systemnamespace. This statement causes the message "Welcome!" to be displayed on the screen.
Console.ReadKey()
The last line Console.ReadKey(); is for the VS.NET Users. This makes the program wait for a key press and it prevents the screen from running and closing quickly when the program is launched from Visual Studio .NET.
- Related Articles
- Explain the basic structure of a program in Java?
- What is the basic minimal structure of HTML document?
- Basic Frame Structure of SDLC
- Basic Frame Structure of HDLC
- What is a structure in C#?
- Structure and Members of the C# Program
- What is the structure of a flower?
- C++ Program Structure
- What is the three basic part of a cell?
- What is union of structure in C language?
- What is the structure of matter?
- Basic calculator program using C#
- What is the full form of BASIC ?
- Basic Operations for Queue in Data Structure
- C program to compare the structure variables
