Compile and Execute C# on Ubuntu Linux
To explain how to compile and execute C# code on Ubuntu, we will create a hello world method for adding two numbers and show the result after the hello world message. We create the file hello.cs with the following content: using System; //Declare namespace namespace HelloWorldApp { //Declare HelloWorld class class HelloWorld { //Add method for adding two numbers public int Add(int a, int b) { return (a + b); } //Main method static void Main(string[] args) { //Print Hello World! message Console.WriteLine("Hello World!"); //Create HelloWorld class object HelloWorld hw = new HelloWorld(); //Calling Add method from the HelloWorld(hw) object, adding 1 + 2 int adding = hw.Add(1,2); //Prints the adding variable Console.WriteLine(adding); } } } Install mono-complete package: $ sudo apt install mono-complete Compile the hello.cs script, in order to generate the hello.exe file $ mcs -out:hello.exe hello.cs Execute the hello.e