Skip to content
Related Articles
Open in App
Not now

Related Articles

How to Compile, Decompile and Run C# Code in Linux?

Improve Article
Save Article
  • Last Updated : 02 Nov, 2022
Improve Article
Save Article

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:// –recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF

echo deb 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.


using System;
public class GFG {
    static public void Main()
        Console.WriteLine("Hello World!");


Hello World!

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


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


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


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

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!