A Simple C# Console Application
A Console Application is one that looks like a DOS window. If you don't know what these are, click your Start menu in the bottom left of your screen. Click on Run. From the dialogue box that appears, type cmd:
![The Run Box in Windows XP](http://www.homeandlearn.co.uk/csharp/images/c1RunBoxCMD.gif)
In Vista and Windows 7, type cmd in the search box at the bottom of the start menu. In Windows 8, the search box is on the Start Screen page. You'll then see the search results appear:
![CMD search in Windows 7](http://www.homeandlearn.co.uk/csharp/images/csharp_2010/cmd_search.gif)
Click cmd.exe to see the console appear.
Click OK and you'll see a black screen, like this one:
![A DOS Window](http://www.homeandlearn.co.uk/csharp/images/c1DOSWindow.gif)
This is the type of window you'll see for our Console Application. When you create your Windows forms, there's a whole lot of code to get used to. But Console Applications start off fairly simple, and you can see which part of the programme is the most important.
So with Visual C# Express open, click File from the menu bar at the top. From the File menu, selectNew Project (or click the New Project link on the left of the opening screen in versions 2010 and 2012):
![New Project menu in C# 2010](http://www.homeandlearn.co.uk/csharp/images/csharp_2010/file_new_project.gif)
When you click on New Project, you'll see the following dialogue box appear:
![The New Project dialogue box in C# Express](http://www.homeandlearn.co.uk/csharp/images/c1NewConsoleProject.gif)
Or this one in version 2010 of the software:
![New Console application in C# 2010](http://www.homeandlearn.co.uk/csharp/images/csharp_2010/newProject_console_small.gif)
For 2012 users, click on Templates from the list on the left. Under Templates, click on Visual C#. You'll then see Console Application appear in the middle:
![A New Console Project in C# 2012](http://www.homeandlearn.co.uk/csharp/images/csharp_2012/chapter_1/new_project_console.gif)
For all versions, the New Project dialogue box is where you select the type of project you want to create. If you only have the Express edition of Visual C#, the options are limited. For the rest of this book, we'll be creating Windows Applications. For now, select Console Application. Then click OK.
When you click OK, a new Console Application project will be created for you. Some code should be displayed:
![The Coding Window in Visual C# Express](http://www.homeandlearn.co.uk/csharp/images/csharp_2012/chapter_1/console_first_project_IDE.gif)
As well as the code, have a look on the right hand side and you'll see the Solution Explorer. This is where all the files for your project are. (If you can't see the Solution Explorer, click View from the C# menu bar at the top. From the View menu, click Solution Explorer.)
The code itself will look very complicated, if you're new to programming. We'll get to it shortly. For now, right click the Program.cs tab at the top, and click Close from the menu that appears:
![Close the Program](http://www.homeandlearn.co.uk/csharp/images/c1ProgramTab.gif)
Or just click the X in C# 2010 and 2012:
![Close Program](http://www.homeandlearn.co.uk/csharp/images/csharp_2010/close_program.gif)
Now double click the Program.cs file in the Solution Explorer:
![The Solution Explorer in C# Express](http://www.homeandlearn.co.uk/csharp/images/c1ProgramSE.gif)
When you double click Program.cs, you should see the code reappear. So this code is the programme that will run when anyone starts your application.
Now click the plus symbol (arrow symbol in version 2012) next to Properties in the Solution Explorer above. You'll see the following:
![The Properties option in the Solution Explorer](http://www.homeandlearn.co.uk/csharp/images/c1PropertiesSE.gif)
The file called AssemblyInfo.cs contains information about your programme. Double click this file to open it up and see the code. Here's just some of it:
![AssemblyInfo.cs](http://www.homeandlearn.co.uk/csharp/images/c1AssemblySE.gif)
The reddish colour text is something you can change. You can add a Title, Description, Copyright, Trademark, etc.
But right click the AssemblyInfo.cs tab at the top, and click Close from the menu. Now, in the Solution Explorer, click the plus symbol next to References:
![Console Application references](http://www.homeandlearn.co.uk/csharp/images/csharp_2010/references.gif)
These are references to code built in to C# (you won't see as many entries in earlier versions of the software). Much later, you'll see how to add your own files to this section.
Before we add some code, let's save the project
No comments:
Post a Comment