C#
C# Stack with Example
What is Stack in C#? The stack is a special case collection which represents a last in first out...
C# is one of the languages provided by Microsoft to work with .Net. This language encompasses a rich set of features, which allows developing different types of applications.
C# is an object-oriented programming language and resembles several aspects of the C++ Language. In this tutorial, we see how to develop our first application.
This will be a basic console application, we will then explore different data types available in the C# language as well as the control flow statements.
A console application is an application that can be run in the command prompt in Windows. For any beginner on .Net, building a console application is ideally the first step to begin with.
In our example, we are going to use Visual Studio to create a console type project. Next, we are going to use the console application to display a message "Hello World". We will then see how to build and run the console application.
Let's follow the below mentioned steps to get this example in place.
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.
If the above steps are followed, you will get the below output in Visual Studio.
Output:-
Step 3) Now let's write our code which will be used to display the string "Hello World" in the console application.
All the below code needs to be entered into the Program.cs file. The code will be used to write "Hello World" when the console application runs.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DemoApplication
{
class Program
{
static void Main(string[] args)
{
Console.Write("Hello World");
Console.ReadKey();
}
}
}Code Explanation:-
Step 4) Run your .Net program. To run any program, you need to click the Start button in Visual Studio.
If the above code is entered properly and the program is executed successfully, the following output will be displayed.
Output:
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.
Summary
What is Stack in C#? The stack is a special case collection which represents a last in first out...
In this tutorial, you will learn- Inheritance Polymorphism What is Inheritance in C#? Inheritance is...
C# is based on the C++ programming language. Hence, the C# programming language has in-built...
C# has a wide array of file operations. These operations include opening a file, reading or...
What is an Interface Class? Interfaces are used along with classes to define what is known as a...
In C# file operations, normally streams are used to read and write to files. A stream is an...