Using Notepad and csc.exe to compile c# Program

Step1
Open Notepad  and type the following code and store it as demo1.cs or in any name.cs

using System;


class demo1
{
    static void Main(String[] x)
    {
        Console.WriteLine("Hello Learners, Welcome to C#");
    }
}

Note: By default, in Notepad, there will not be any auto-formatting. all the codes will be displayed in black color. If you want to have auto-formatting you can use notepad++.

If you have stored this program in folder name sampleprograms  of  "c" drive then, your working folder is c:\sampleprograms

Step2

Open Visual Studio command prompt or Developer command prompt from Start menu

It will display some path like this, give DOS command CD\

C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional>CD\ 

Note: CD\ means change directory to ROOT, that is to C:\>

Step3

Copy and paste the working folder name sampleprograms in command prompt, Now it will apper like below

c:\sampleprograms>

give DOS Command dir to list the directory contents you can see your file

Step4

Now give the following command like below

c:\sampleprograms>csc demo1.cs

you will get the same prompt again as below if your program does not have any errors.

c:\sampleprograms>

type demo1 in the prompt then you will get the output

c:\sampleprograms>demo1
Hello Learners, Welcome to C#

c:\sampleprograms>

I hope you learned how to compile and run C# Program without visual studio using notepad and csc.exe compiler.  thanks.






No comments:

Post a Comment