C# is a general-purpose, modern and object-oriented programming language pronounced as “C sharp”. C# is among the languages for Common Language Infrastructure and the current version of C# is version 8.0. C# is a lot similar to Java syntactically and is easy for the users who know C, C++ or Java.
Since the C# is a lot similar to other widely used languages syntactically, it is easier to code and learn in C#.
Programs can be written in C# in any of the widely used text editors like Notepad++, gedit, etc. or on any of the compilers. After writing the program save the file with the extension .cs. There are various online IDEs such as GeeksforGeeks ide, CodeChef ide, etc. which can be used to run C# programs without installing. One can also use command-line options to run a C# program.
Sample C# Program to execute on Command-Line:
Setting up the Environment for C# Compiler
Step 1: Go to Control Panel -> System and Security -> System. Under Advanced System Setting option click on Environment Variables as shown below:
Step 2: Now, we have to alter the “Path” variable under System variables so that it also contains the path to the .NET Framework environment. Select the “Path” variable and click on the Edit button as shown below:
Step 3: We will see a list of different paths, click on the New button and then add the path where .NET Framework is installed.
Step 4: Click on OK, Save the settings and it is done !! Now to check whether the environment setup is done correctly, open command prompt and type csc.
Steps to Execute C# Program on cmd
Step 1: Open the text editor like Notepad or Notepad++, and write the code that you want to execute. Now save the file with .cs extension.
Step 2: Compile your C# source code with the use of command:
If your program has no error then it will create a filename.exe file in the same directory where you have saved your program. Suppose you saved the above program as Hello.cs. So you will write csc Hello.cs on cmd. This will create a Hello.exe file.
Step 3: Now there are two ways to execute the Hello.exe. First, you have to simply type the filename i.e Hello on the cmd and it will give the output. Second, you can go to the directory where you saved your program and there you find filename.exe. You have to simply double-click that file and it will give the output.
- Using Command:
- Using .exe file:
- Hello World Program : First program while learning Programming
- Program to convert Byte array to IP Address
- Program to calculate Electricity Bill
- Program to print half Diamond star pattern
- Program to swap numbers using XOR operator in C#
- Program to Print a New Line in C#
- Program to Print Backslash () in C#
- Program to define various types of constants in C#
- Program to Input Weekday Number and Print the Weekday in C#
- C# Program to Convert the Octal String to an Integer Number
- C# Program to Convert a Binary String to an Integer
- C# Program for Nested Conditional Operator
- C# Program for Converting Hexadecimal String to Integer
- Differences Between .NET Core and .NET Framework
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.