- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Beginning C# programming with Hello World
The following is a simple “Hello World” program in C# programming −
Example
using System; namespace MyHelloWorldApplication { class MyDemoClass { static void Main(string[] args) { // display text Console.WriteLine("Hello World"); // display another text Console.WriteLine("Welcome!"); Console.ReadKey(); } } }
Output
Hello World Welcome!
Let us see now what all it includes −
- using System − the using keyword is used to include the System namespace in the program.
- namespace declaration − A namespace is a collection of classes. The MyHelloWorldApplication namespace contains the class HelloWorld.
- The class MyDemoClass contains the data and method definitions that your program uses. Classes generally contain multiple methods.
- The Main method 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("Hello World");
- WriteLine is a method of the Console class defined in the System namespace. This statement causes the message "Hello, World!" to be displayed on the screen. Add more text using the same Console.WriteLine(); in C#.
- Console.ReadKey(); It 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.
Advertisements