How to run the C# program from Commandline using csc.exe ?

Published on July 8, 2016 by abundantcode

Filed under C#, Foundation (General)

Last modified July 8, 2016

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 0 (0 votes)

This article have been viewed 908 times

Problem Statement

You need to use he csc.exe (C# command line compiler) to compile the Csharp program from Command prompt.


Use the command prompt and use the csc.exe to compile and run the program from the command prompt.

Follow the below steps to compile and run the C# program from command prompt.

1. Type the program in the notepad and save it as hello.cs under D:\kedo folder.

Below is the sample code that can be in the notepad file.

using System;
public class Program
    public static void Main(string [] args)
        Console.WriteLine("Hello world");

2. Compile the program by typing the following

C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc hello.cs

Here , csc is the name of the csharp file which is usually found in the path

C:\Windows\Microsoft.NET\Framework\<.NET Framework Version>

3. Once the compilation is successful , you can enter the name of the file with the .exe extension


If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Comment


You might be Interested in these Posts

How to Get the number of elements in ArrayList in C# ?

Here's the code that demonstrates how one can get the total number of elements contained in the Arra...

How to Check if the ArrayList is read-only in C# ?

There are times when you would use the read-only wrapper in order to prevent modifying the ArrayList...

How to Add range of elements to ArrayList in C# ?

You can use the AddRange method of the ArrayList object to add the range of elements (string array) ...