How to use Command Prompt (cmd) to get the output of C# program rather than Microsoft Visual Studio ?

We use Microsoft Visual Studio for the Programming of C# Language. But there is also a way to get output in command Prompt of  Code written in Traditional Notepad.
For that we make use of "csc" in Windows Command prompt" (csc : Csharp Compiler is a command for compiling the code)


So lets start,

Step 1) Open Windows File Explorer (My Computer).
Go to the Location " Local Disk C:\ >> Windows >> Microsoft.NET >> Framework 64 >> Framework >> v4.0.xx "
and Copy this path.


Step 2) Open Control Panel.
Go to "System and Security >> System >> Advanced System Settings >> Environment Variables "
Click on New.
In "Variable Name" type "PATH".
In "Variable Value" Copy paste the address location we have done in Step 1.






Step 3) Open Command Prompt and type "csc". If you getting something like in the image below than you have properly configured the environment variable.


Step 4) Open Notepad and start typing simple HelloWorld Program and save it in ".cs" extension
 (for,  HelloWorld Program syntax go to this link : https://csharpisbetter.blogspot.com/2018/08/how-to-build-compile-and-run-your-first.html )



Step 5) Open Command Prompt and go to the location where you saved the file "HelloWorld.cs
For that type "cd  folder_location"


Step 6) now type "csc filename.cs"
in our case "csc HelloWorld.cs"
This command is used to compilation of the code
(If there is any error compiler will show where the error is with line number )

Step 7) Now type HelloWorld "without any extension"
You will get the output !


Click on an Image to enlarge and see it properly ;-)


Comments

Popular posts from this blog

How to Build, Compile and Run your first Program in C# ?