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 5109 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

Leave a Comment


x

You might be Interested in these Posts

How to get the AM or PM value from a DateTime object in C# ?

There are times when you might want to get only the string AM or PM from the DateTime object that yo...

C# Program to swap two numbers without using temporary variable

Problem Write a program in Visual CSharp to swap two numbers using temporary variable and display t...

C# Program to print the sum of two numbers

Problem Write a program in C# to add two numbers and display the result in copnsole window. How to...