02 - Getting Started with C#

2.1 Development tools for C# programming

Microsoft provides the various development tools for C# programming. The list of the tools is as mentioned below:

  • Visual Studio 2010
  • Visual C# 2010 Express
  • Visual Web Developer

The Visual Studio tool is the collection of services that helps user for creating variety of applications. It is helpful for connecting all projects, teams. It is flexible and integrated and helps user to develop products effectively.

User can download the trial version of Visual Studio software from the Official Microsoft website.

Visual C# 2010 Express is the popular version used for the development among the users. It is a free software and easy to use.

User can download the tool from the Microsoft Visual 2010 express site.

Visual Web developer offers a rich editor for creating C#, ASP.NET, HTML, CSS, etc applications. It is free development environment. It provides intellisense feature, debugging support, supports web development and database development.

User can download the tool from Microsoft Visual Web developer official website.

2.2 User Interface elements of Visual Studio in .NET

Whenever the user works with the project in Visual Studio .NET, there are elements available in the application. The elements are as mentioned below:

1) The Start Page

2) Solution Explorer window

3) Output Window

4) Class View Window

5) Code Editor Window

6) Error List Window

7) Standard ToolBar

1) The Start Page: When the user starts the Microsoft Visual Studio, the start page is displayed.

The following figure shows the start page of Visual Studio:

The start page is the default page for the browser provided with Visual Studio .NET. The tasks performed by it are specifying preferences, searching information about new features and communicating with developers on .NET platform.

When the user opens the Visual Studio application, the Projects tab is selected by default on the Start page. User can view any projects displayed on the screen.

2) Solution Explorer Window: The Solution Explorer window is used to list the solution name, the project name, and all the classes added in the project. User can open a particular file by double clicking the file in the Solution Explorer window.

The Solution Explorer Window is as shown below:

3) Output Window: The Output Window displays messages for the status of various features of Visual Studio .NET. When the application is compiled, the output window displays the current status. The number of errors occurred during the compilation are displayed.

The following figure shows the Output Window:

4) Class View Window: The Class View window displays classes, methods, and properties associated with the respective file. The hierarchical structure of items is displayed.

The Class View window has two buttons, one for sorting the items and other for creating the new folder. The following figure shows the Class View window:

 

5) Code Editor Window: The Code Editor Window allows the user to enter and edit code. User can add code to the class using this editor. The following figure shows the Code Editor window for Visual Studio.

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

namespace sumofnumbers
{
    class Program
    {
        static void Main ( string[ ] args )
        {
            int sum, a,b;
            Console.Write(“Enter the value of a”);
            a = Convert.ToInt32(Console.ReadLine());
            Console.Write(“Enter the value of a”);
            b = Convert.ToInt32(Console.ReadLine());
            sum = a + b;
            Console.WriteLine(“The sum is”+ sum );
            Console.Read();
        }
    }
}

6) Error List Window: The Error List Window displays the list of errors along with the source of the error. It identifies the errors as you edit or compile the code. User can locate the source of the error by double clicking the error in the Error List Window. User can open the Error list window by clicking View -> Error List window.

The Error List window is as shown below:

7) Standard ToolBar: The standard toolbar is located below the menu bar. It provides the shortcut menus for the commands. The buttons include tasks such as open a new or existing file, saving or printing a file, cutting and pasting text, undoing and redoing the recent actions.

The following table lists the name and functions of the various tools of the Standard ToolBar.

Name

Button

Function

New Project

It creates a new project

Add New Item

It adds new item in the project

Save

It saves the program

Save All

It saves all the unsaved items of the application

Cut

It places the selected text or objects on the Windows Clipboard

Copy

It places a copy of selected text or objects on the Windows Clipboard

Paste

It pastes the contents of Clipboard on the document

Start Debugging

It compiles and executes the current project

2.3 Compiling and Executing the Project

To compile and execute the application, you need the perform the following steps:

1) Create the application in Visual Studio .NET.

2) Select the application created by the user.

3) Select ‘Build’ - > ‘Build Solution’ option to compile the application

To execute the project there are several methods as mentioned below:

1) Select the F5 key

2) On the menu bar, choose the ‘Debug’ option. Click ‘Start Debugging’ option

3) On the Toolbar, select ‘Start Debugging’ button which appears as follows:

When the user wants to stop the program, select one of the following methods:

1) On the Toolbar, choose ‘Stop Debugging’ button

2) On the menu bar, select ‘Debug’, click ‘Stop Debugging’ option

2.4 C# Console Application

Console applications can be easily created in C#. They are used for reading input and provide a specific output. It does not have a graphical user interface. They have a character based interface.

To write the console application, you need to use a class called Console. The class is available in the System namespace.

The steps to create the console application are as mentioned below:

From the start page, click ‘New Project’ option

2) Select the ‘Console Application’ option from the list

3) Add appropriate name to the image and click ‘OK’

4) Add the code in the class created by the user

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

namespace sumofnumbers
{
    class Program
    {
        static void Main ( string[ ] args )
        {
            int sum, a,b;
            Console.Write(“Enter the value of a”);
            a = Convert.ToInt32(Console.ReadLine());
            Console.Write(“Enter the value of a”);
            b = Convert.ToInt32(Console.ReadLine());
            sum = a + b;
            Console.WriteLine(“The sum is”+ sum );
            Console.Read();
        }
    }
}

5) Execute the code and the output displayed is as shown below:

Like us on Facebook