Wednesday 17 September 2014

How and why Run C# in CMD

1).To run C# Code in cmd
  1. Write code in notepad.
  2. save it by .cs extension.
  3. download .net framework its free (http://filehippo.com/download_dotnet_framework_4)  or try other sites also
  4. Install .net framework
  5. Open cmd
  6. set path of cmd by using (set path="")  command.
  7.                generally:  C:\Windows\Microsoft.NET\Framework\v4.0.30319
  8. Now go to the folder (by using cmd) in which you save your c# file which you create in step 2.
  9. Now enter  csc "your file name."cs  in cmd.
  10. 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
Snapshot of output
Fig 1: Snap shots of output