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

Published on July 8, 2016 by abundantcode

Filed under C#

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 2341 times

Problem Statement

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

Solution

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

image

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


x

You might be Interested in these Posts

C# and Lambda – Filter elements from object collection with Logical Operators

Here’s a sample code snippet demonstrating how to filter elements from a list of objects using the w...

C# and LINQ – Filter elements from object collection with Logical Operators

Here’s a sample code snippet demonstrating how to filter elements from a list of objects using the w...

C# and Lambda – Filter elements from object collection using Where method

Here’s a sample code snippet demonstrating how to filter elements from a list of objects using the w...