Write a Console Application for beginners


.NET framework contains Console application,Windows applications usually called as Win Apps,Web applications,Mobile applications,Web Services.Let us know how to write a simple Hello World using Console Application in the Visual Studio.NET framework tool 2008.

1.Click Start->Programs->Microsoft Visual Studio 2008.
2.In MS Studio 2008 menu you have sub menus like
i)Visual Studio Remote Tools.
ii)Visual Studio Tools.
iii)Microsoft Visual Studio 2008.
iv)Microsoft Visual Studio 2008 Documentation.

3.From the sub menu click Microsoft Visual Studio 2008,the Editor opens which takes couple of minutes.

4.When the Editor opens you find File,Edit,View,Tools,Test,Window,Help menu on the top left hand side of the Editor.
5.From the menus,Click File->New->Project.
6.A new Dialog box with the name NewProject(seen on the top left hand side of the dialogbox) will be opened.
7.The dialogbox contains
1) Project types - indicates which language you would like to prefer which starting a project.(The project is stored in the disk with the extension .PRJ)
2) Templates - indicates which design application you would like to have in starting up a project.
3)At the right hand top of the dialogbox you can see the framework you want to start a project.In VS2008,you have the option like
i).NET Framework3.5.
ii).NET Framework3.0
iii).NET Framework2.0
4)In the lower bottom,dialogbox contains Name,Location and SolutionName with ok and Cancel button on the right lower bottom.

8.Now as a beginner select the Project type,in my case i will select C# and in the templates i will select ConsoleApplication.
9.By giving name and Location to the Application,i click ok button.It takes few seconds to open up the project the name you have given(test here).
10. After opening,you can see Solution explorer with the name you have given and a CS file as Program.cs( which is a default file when you are trying to open a Console Application).

As you are fresher in .NET,let us start with a simple program and small program.



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace test
{
class Program
{
static void Main(string[] args)
{
Console.Write("HelloWorld \n");
}
}
}


In the above code,the sentences starting with "using" are called header files.We have to remember them.There is no other alternative.In .NET these are termed as namespaces.From these namespace,you have tons of classes.For example Console comes from System namespace.If you are not interested to use header files than you have to write "System.Console" in the code separately.Obviously class have methods(System.Console.Write).So in other way by removing header files,you can write the code as


namespace test
{
class Program
{
static void Main(string[] args)
{
System.Console.Write("HelloWorld \n");
}
}
}


This kind of writing the code is helpful for you in learning stage.But if you are doing big big projects,than it would be always helpful for you to write the header files in the beginning.So,that it improves the performance issues.

Till now we have seen how to write the code.
Now let us see how to debug the program and viewing the output.They are two ways to debug the program.

1)Just pressing F5 or pressing from the Debug menu.
2)Just pressing Ctrl+F5 or from the Debug menu which has start without Debugging submenu in the Debug menu.

The output for the above code is:
o/p:
in the command prompt:

HelloWorld
Press any key to continue.........

Interesting point here:

a) After executing,usually each and every programming languages stores the results in a well formed packed format termed as executable file.If you are curious to know where this executable file is stored.Here is the solution.Just do what i did like

"C:\Documents and Settings\*UserName\My Documents\Visual Studio 2008\Projects\test\bin\Debug"

*UserName:differs from system to system.(Just see in which user,your My Documents folder is stored i.e. the UserName for you.)

i)In the Debug folder you find executable file("test.exe").Just click on the "test.exe") you find the output of it.You can carry this ".exe" file any where you want and run it without taking the whole source code.

Note:
Technical Stuff:
Q) The main difference between "Start with debug(F5)" and "Start without debugging(Ctrl+F5)" in Visual Studio is:
A)
i)if you want to know step by step flow of the program,you can use "F5".(by applying breakpoints(F9) whereever you want).While executing, you can see the step by step executing process of the program you wrote and displays the output in the output screen.
ii)if you dont want to know step by step flow of the program,you can simply use "CTRL+F5",(even if you apply breakpoints(F9)).While executing,you can't see the step by step executing process of the program.

Conculsion:
I hope as a fresher,you would understand the step by step procedure of writing a simple code in .NET Visual Studio Console Applications.If you have any queries please let me know.


Related Articles

More articles: Console application Windows application VS 2008 Framework 3.5

Comments

Author: Fool To Code31 May 2010 Member Level: Gold   Points : 0

great, nice tutorial for beginners



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: