Run C# code on linux terminal

c#, linux, shell

Solution

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!

Problem

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 _SmsID) { ClassGlobal._client = new TcpClient(_IPaddress, Convert.ToInt32(_Port)); ClassGlobal.SMSID = _SmsID; string _result = SendToCAS(_IPaddress, _Port, _SmsID ); if (_result != "") return (_result); string _acoknoledgement = GetFromCAS(); return _acoknoledgement; } ``` When I run a shell bash I use `#!/bin/bash`. There is how to do the same with C#?

Original source