
- 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 are the main parts of a C# program?
The main parts of a C# program includes −
- Namespace declaration
- A class
- Class methods
- Class attributes
- A Main method
- Statements and Expressions
- Comments
The following is an example showing how to create a C# program −
Example
using System; namespace Demo { class Program { static void Main(string[] args) { Console.WriteLine("Our first program in C#!"); Console.ReadKey(); } } }
Output
Our first program in C#!
Here are the parts of the C# program we saw above −
using System; - the using keyword is used to include the System namespace in the program. A program generally has multiple using statements.
Namespace declaration. A namespace is a collection of classes. The Demo namespace contains the class Program.
The next line has a class declaration, the class Program contains the data and method definitions that your program uses. Classes generally contain multiple methods. Methods define the behavior of the class. However, the Program class has only one method Main.
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.
The Main method specifies its behavior with the statement Console.WriteLine("Our first program in C#!");
WriteLine is a method of the Console class defined in the System namespace. This statement causes the message “Our first program in C#!” to be displayed on the screen.
- Related Articles
- What are the alimentary canal and its main parts?
- What are the parts of a flower?
- What are the reproductive parts of a woman?
- What are the parts of a Compound Microscope?
- What are the parts of the nose?
- What are the main features of JDBC?
- What are the main features of MySQL?
- What are the main components of Soil?
- What are parts of ear?
- What are the major parts of the brain? Mention the functions of different parts?
- What are the Main Characteristics of Scientific Management?
- What are the main types of chemical reactions?
- What are the main features of collenchyma tissue?
- What Are the Main Advantages of Citrix Xenserver?
- What are the parts of the Male reproductive system?
