How to debug or execute C# program in Notepad and VS?

execute
In this chapter you will learn:

  • How to compile and run c# code in notepad as well as visual studio?
  • How to run C# code in notepad as well as visual studio?

It has been seemed with various beginners that they are able to understand C# concept but they got failed while implementing their logic into program. The best way to get rid of this types of problem is practice. So, just understand the program that is mentioned below and try to run C# code on your system.

Using Notepad

Step 1: Open Notepad and write the following c# code carefully.

Step 2: Now save this program as Chapter1.cs in csharp Folder in D drive (Create csharp Folder in D Drive). You must choose All Files in save as type box.

Save As

Step 3: Go to Start > All Programs > Microsoft Visual Studio 2005 or 2008 > Visual Studio Tools > Visual Studio 2005 or 2008 Command Prompt.

Open VS CMD

Step 4: Set Path in command prompt where your Chapter1.cs file is saved. Here we are using D:/csharp.

  • Type D: and hit Enter
  • Now type cd csharp and hit Enter
  • You are in Csharp Folder now.
Setting environment for using Microsoft Visual Studio 2008 x86 tools.
C:\Program Files Microsoft Visual Studio 9.0\VC>D:
D:\>cd csharp
D:\csharp> __

Step 5: Now compile your program by following command:

Setting environment for using Microsoft Visual Studio 2008 x86 tools.
C:\Program Files Microsoft Visual Studio 9.0\VC>D:
D:\>cd csharp
D:\csharp>csc Chapter1.cs
Microsoft Visual C# 2008 Compiler version 3.5.30729.4926 for Microsoft .NET Framework version 3.5 Copyright Microsoft Corporation. All rights reserved.
D:\csharp> __

You will see some information like compiler version number and framework information. There is no error, so you won’t get any error.

Step 6: Now, it’s turn to C sharp program. Just write your file name without extension and hit enter.

Setting environment for using Microsoft Visual Studio 2008 x86 tools.
C:\Program Files Microsoft Visual Studio 9.0\VC>D:
D:\>cd csharp
D:\csharp>csc Chapter1.cs
Microsoft Visual C# 2008 Compiler version 3.5.30729.4926 for Microsoft .NET Framework version 3.5 Copyright Microsoft Corporation. All rights reserved.
D:\csharp>Chapter1
This is my First C# Program
__

Step 7: You will get the This is my First C# Program as output.

Using Visual Studio 2005/2008/2012 or any version

Visual Studio is easiest way to handle C# code. To execute the program on visual studio, go through the following steps:

Step 1: Launch Visual Studio and go to File > New Project

New Project

Step 2: Select Visual C# in left pane and then choose Console Application.

New Project

Step 3: Select your location where you want to save the file and then clickOK.

New Project

Step 4: Visual Studio will open a code editor window including some necessary code.

Step 5: Now write the above mentioned code and press F5 to run C# code.

Step 6: You will see the same output in Visual Studio Command Prompt.

 

Summary

In this chapter you learned how to write C# code in notepad as well as visual studio environment. You also learned how to execute your program in both environments. In next session, you will learn about variables and data types in C#.


4 thoughts on “How to debug or execute C# program in Notepad and VS?”

    1. Hello Priya ! this is Yogesh. You can write your C# program in any text editor as you want but you have to have the dot net framework installed in the system which consists “csc.exe”, the compiler of C#.

Leave a Reply

Your email address will not be published. Required fields are marked *