How to Compile, Decompile and Run C# Code in Linux?
Last Updated :
02 Nov, 2022
C# is a modern multi-paradigm programming language developed by Microsoft and released in the year 2000. By multi-paradigm we mean that it includes static typing, strong typing, lexically scoped, imperative, declarative, functional, generic, object-oriented, and component-oriented programming disciplines. The syntax of C# is highly inspired by the JAVA syntax, therefore, it is easier to understand for most developers who have some basic knowledge of C, C++, and JAVA. It was designed by Anders Hejlsberg and developed by Mads Torgersen.
To compile, Decompile and Run C# code in Linux, follow the below-mentioned steps:
Firstly, we need to install mono-complete, to run software for Mono or Microsoft. NET.
Step 1: To Install mono-complete, open up your Linux terminal and type the following command, and hit enter.
Run the following command to set up the system before installing the mono.
sudo apt install gnupg ca-certificates
sudo apt-key adv –keyserver hkp://keyserver.ubuntu.com:80 –recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
echo deb https://download.mono-project.com/repo/ubuntu stable-focal main | sudo tee /etc/apt/sources.list.d/mono-official-stable.list
sudo apt update
Then run the following to install mono.
sudo apt install mono-complete
Step 2: Write a simple hello world program in C# and save the code in a file called geeks.cs.
C#
using System;
public class GFG {
static public void Main()
{
Console.WriteLine( "Hello World!" );
Console.ReadKey();
}
}
|
Step 3: Now make this C# file an executable file. Navigate to the file and run the following command.

making executable
sudo chmod +x geeks.cs
Here, +x means executable.
Step 4: Now we will be using the MCS compiler and creating a Windows executable named geeks.exe from the source geeks.cs.
mcs -out:geeks.exe geeks.cs
Output:

compiling c# code
After this, an executable file, geeks.cs, will be generated.
Step 5: Now to run this geeks.exe executable file, run the following command.
mono geeks.exe
Output:

Running c# code
Step 5: Press Enter to exit back to a default terminal prompt.
Step 6: To decompile this executable file run the following command:
monodis –output=geeks.txt geeks.exe
Output:

Decompiled c# code
The decompiled code will be saved in the newly generated file, geeks.txt. To view the decompiled file in the terminal, run the following command:
cat geeks.txt
Output should look like this:

The output of decompiled code
Similar Reads
How To Compile And Run a C/C++ Code In Linux
C Programming Language is mainly developed as a system programming language to write kernels or write an operating system. C++ Programming Language is used to develop games, desktop apps, operating systems, browsers, and so on because of its performance. In this article, we will be compiling and exe
4 min read
How to Install GCC Compiler on Linux?
In this article, we will discuss how to install a GCC compiler on Linux. GCC stands for GNU Compiler Collections which is used to compile mainly C and C++ language. It can also be used to compile Objective C and Objective C++. The GCC is an open-source collection of compilers and libraries. Let's st
2 min read
How to Compile and Run C program in Terminal?
To efficiently compile and run C programs, users typically utilize a compiler or the built-in terminal. The command prompt (CMD) on Windows can be employed to process C programs and generate the desired outputs. To create an executable C program, users must compile their C code using the system term
6 min read
How to Install Code Blocks for C++ on Linux?
Code::Blocks is a free IDE( an integrated development environment), for C/C++ and FORTRAN languages. It is a cross-platform IDE and available for Windows, Mac, and Linux, In this article, we are going to discuss various methods using which we can install Code Blocks on Linux.: Installation Code Bloc
2 min read
How to Configure C/C++ on AWS EC2?
AWS or Amazon web services is a cloud service platform that provides on-demand computational services, databases, storage space, and many more services. EC2 or Elastic Compute Cloud is a scalable computing service launched on the AWS cloud platform. In simpler words, EC2 is nothing but a virtual com
2 min read
automake command in Linux with Examples
automake is a tool used for automatically generating Makefile.in files compliant with the set GNU Coding Standards. autoconf is required for the use of automake. automake manual can either be read on-line or downloaded in the PDF format. More formats are also offered for download or on-line reading.
1 min read
gzexe command in Linux with examples
gzexe command is used to compress executable files and also used to automatically uncompress and execute the files. This utility is very useful on systems having small disk space. This command creates two files. Suppose you run it for a file named grs then it will create two files like: grs~ : Origi
1 min read
gcc command in Linux with examples
GCC stands for GNU Compiler Collections which is used to compile mainly C and C++ language. It can also be used to compile Objective C and Objective C++. The most important option required while compiling a source code file is the name of the source program, rest every argument is optional like a wa
2 min read
How Do I Create a Library in C?
Libraries are a collection of code that can be used by other programs. They promote code reuse and modularity. In C, we can create our own libraries. In this article, we will learn how to create a library in C. Creating a Library in CIn C, there are multiple methods using which we can create a libra
3 min read
How to Install NuGet from Command Line on Linux?
NuGet is the package manager for the .NET framework. It's very much useful for developers as developers can create, publish and consume packages. The package format of NuGet consists of a single ZIP file with the extension of .nupkg and which is the DLL compiled code like the packageâs version numbe
2 min read