How to Compile, Decompile and Run C# Code in Linux?
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 from the JAVA syntax, therefore, it is easier to understand for most the developer what 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.
Step 3: Now make this C# file an executable file. Navigate to the file and run the following command.
chmod +x geeks.cs
Here, +x means executable.
Step 4: Now we will be using the mcs compiler and create a Windows executable named geeks.exe from the source geeeks.cs.
mcs -out:geeks.exe geeks.cs
After this, an executable file, geeks.cs, will be generated.
Step 5: Now to run this geeks.exe executable file, run the following command.
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
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:
Output should look like this: