

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- What are the main features of JDBC?
- What are the main features of MySQL?
- What are the main classes and interfaces of JDBC?
- What are the five main sources of electrical energy?
- What are the main file components in Cucumber?
- Proxy vs VPN: What are the main differences?
- What are the four main components and the roles of the UNIX OS?
- What are the main Security Frameworks in information security?
- Program to check two parts of a string are palindrome or not in Python
- What is MySQL Cursor? What are its main properties?
- What is Canva and what are its main features?
- What is the Main Memory?
- What are the main features and enhancements introduced in Java 9?
- What is the proper declaration of main in C++?
- What are the main shift operators provided by Java? Explain with an example?