1).To run C# Code in cmd
- Write code in notepad.
- save it by .cs extension.
- download .net framework its free (http://filehippo.com/download_dotnet_framework_4) or try other sites also
- Install .net framework
- Open cmd
- set path of cmd by using (set path="") command.
- generally: C:\Windows\Microsoft.NET\Framework\v4.0.30319
- Now go to the folder (by using cmd) in which you save your c# file which you create in step 2.
- Now enter csc "your file name."cs in cmd.
- Now if you set correct path and your coding is correct then a .exe file is created run that file on cmd.
2). Why use cmd instead of visual studio
- Visual studio is paid while .net framework is free.
- Since C# OFFER programmers to to run on a variety of Operating System platforms. Although right now there is essentially just one C# compiler available from microsoft in future there will be other platform such as UNIX, LINUX , MACINTOSH thats why we use notepad and cmd for programming.
Here is a sample to run a code in cmd
Fig 1: Snap shots of output |