Run C# code on linux terminal

后端 未结 5 1979
慢半拍i
慢半拍i 2020-12-24 07:47

How can I execute a C# code on a linux terminal as a shell script.

I have this sample code:

public string Check(string _IPaddress,string _Port, int _         


        
5条回答
  •  太阳男子
    2020-12-24 07:58

    Of course it can be done and the process is extremely simple.

    Here I am explaining the steps for Ubuntu Linux.

    Open terminal:

    Ctrl + Alt + T

    Type

    gedit hello.cs
    

    In the gedit window that opens paste the following example code:

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

    Save and close gedit.

    Back in terminal type:

    sudo apt update
    sudo apt install mono-complete
    mcs -out:hello.exe hello.cs
    mono hello.exe
    

    Output:

    Hello World!
    

提交回复
热议问题