- Back to Home »
- C#.NET »
- Creating Console Application using Visual Studio
Posted by :
Sudhir Chekuri
Wednesday, 30 December 2015
Console application: It is a CUI (Character user interface) or TUI (Text based user interface) application in which user can interact with the application using keyboard only. It is an exe application which has to be installed in a system to use that application in that system. It is DOS based application like C and C++.
Example: Train enquiry software which takes train no to show the availability.
1. Open Visual Studio
Figure: VisualStudio
2. Click on new project
3. Select a language as c# from the left side
4. Select console application from the list of applications.
Figure: Console 2
5. Give the name to the project
6. Select the location to save the project. click on ok.
Now default environment to create console application is displayed.
7. F5 is the shortcut key to start debugging or to execute a program (or) click on play symbol button present in the center of top menu of visual studio tool.
8. Shift + F5 for stop debugging or execution.
Basic C#.NET program structure in Console Application
Program
using System;
namespace first
{
class Program
{
static void
Main(string[] args)
{
}
}
}
Explanation:
using - using is a keyword used to import a namespace to use the classes inside it in your coding.
System - System is a namespace name which consists of classes used in coding.
Like System we also have many namespaces given by Microsoft.
If we are not importing namespaces, we have to add namespace name everywhere before class name in the program.
first - first is the project name what you have given while creating this console application.
Program - Program is the default class name for every console application.
Main - Main is the method is acts as the starting point for every application.
There should be only one main function for every project.
Main is a static method which is created using static keyword and as it is a static method memory for main is created in ram when program is executed.
void - void is the return type of Main method.
Method with void return type returns nothing so main method also returns nothing.
string[] args - Main method will take input arguments in the form of string array.
In the above program namespace name is declared as first which is the project name and all the classes inside this project will be created inside that namespace.