This document provides a step-by-step guide to creating and running a simple "Hello World" console application in C# using Visual Studio. It explains how to create a new console project, add the code to display "Hello World", and run the application. Key aspects covered include using classes, the Main method, and Console methods like Write and ReadKey.
Download as PPT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
21 views
Lesson3 First Program
This document provides a step-by-step guide to creating and running a simple "Hello World" console application in C# using Visual Studio. It explains how to create a new console project, add the code to display "Hello World", and run the application. Key aspects covered include using classes, the Main method, and Console methods like Write and ReadKey.
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 13
Prepared
By BAZZEKETA DATSUN MIT(MUK) Tel: 0705333525 Email: [email protected]
By Bazzeketa Datsun 1 C# is an object-oriented programming language
Meaning that its building blocks are objects
and classes.
A class is a blueprint of an object
An object is an instance of a class. We can get many objects from one class
Consider the class as a ‘Parent’ and the
object as a ‘child’. A parent can have many children Objects from the same class have similar attributes and methods. A console application is an application that can be run in the command prompt in Windows.
In this first program,
◦ We are going to use Visual Studio to create a console type project. ◦ Then use the console application to display a message "Hello World". ◦ Then see how to build and run the console application Step 1) The first step involves the creation of a new project in Visual Studio. For that, once the Visual Studio is launched, you need to choose the menu option New->Project. Step 2) The next step is to choose the project type as a Console application. Here, we also need to mention the name and location of our project. Step 2) output. ◦ A project called 'DemoApplication' will be created in Visual Studio. This project will contain all the necessary artifacts required to run the Console application. ◦ The Main program called Program.cs is default code file which is created when a new application is created in Visual Studio. This code will contain the necessary code for our console application. Step 3) Now let's write our code which will be used to display the string "Hello World" in the console application. Step 3) Code explanation. The first lines of code are default lines entered by Visual Studio. The 'using' statement is used to import existing .Net modules in our console application. These modules are required for any .Net application to run properly. They contain the bare minimum code to make a code work on a Windows machine.
Every application belongs to a class. C# is an
object-oriented language, and hence, all code needs to be defined in a self-sustaining module called a 'Class.' In turn, every class belongs to a namespace/project. A namespace/project is just a logical grouping of classes. Step 3) Code explanation. The Main function is a special function which is automatically called when a console application runs. Here you need to ensure to enter the code required to display the required string in the console application.
The Console class is available in .Net which allows
one to work with console applications. Here we are using an inbuilt method called 'Write' to write the string "Hello World" in the console.
We then use the Console.ReadKey() method to read
any key from the console. By entering this line of code, the program will wait and not exit immediately. The program will wait for the user to enter any key before finally exiting. If you don't include this statement in code, the program will exit as soon as it is run. Step 4) Run your .Net program. To run any program, you need to click the Start button in Visual Studio. From the output, you can clearly see that the string "Hello World" is displayed properly. This is because of the Console.write statement causes this string to be sent to the console.
Learn C# From Scratch in One Hour C# Book for Absolute Beginners with Hands On exercises and Real-World Examples the one book you need to quickly Master C# Programming,: No prior experience is required
Learn C# From Scratch in One Hour C# Book for Absolute Beginners with Hands On exercises and Real-World Examples the one book you need to quickly Master C# Programming,: No prior experience is required