Run the C # program with mono in the UBUNTULinux Environment

Source: Internet
Author: User
Step 1 environment (in Ubuntu) sudoapt-getinstallmono-gmcsmono Step 2: Create example. csclassX {staticvoidMain () {System. Console. Write ("Myfirstmonoappworked! \ N ") ;}} step 3 compile gmcsexample. cs Step 4 execute./example.exe In the Lin Step 1 Environment (under Ubuntu)
Sudo apt-get install mono-gmcs mono

Step 2: Create example. cs
Class X {
Static void Main (){
System. Console. Write ("My first mono app worked! \ N ");
}
}

Step 3 compile
Gmcs example. cs

Step 4
./Example.exe

Use C # in Linux (under Fedora)
When Microsoft launched its. NET strategy, one of the goals was to run the software on a variety of different platforms.

Mono, an open-source project that enables. NET to run on your Linux operating system.

If you work with Microsoft and Linux like me, this Mono will help you and me. You can write C # programs on both platforms.

Download the latest Mono installation package from the www.go-mono.com. I read it. When I wrote this article, Mono 1.1.13.8 was the latest Stable version on the official website.

Before installing Mono, you must determine whether you have GIMP Toolkit, Drawing Kit, and pkg-config. You can download them on rpmfind.net. We recommend that you download the latest version. If you have these software on Linux, you may need to upgrade them.

Install the software below:
# Rpm-Uvh glib2-2.0.0-1.i386.rpm
# Rpm-Uvh glib2-devel-2.0.0-1.i386.rpm
# Rpm-Uvh pkgconfig-0.12.0-1.i386.rpm

Next, extract Mono:
# Tar-zxvf mono-1.1.13.8.tar.gz

Next:
#./Configure
# Make
# Make install

After all The above is done, your Linux system will have a working Mono, which includes The Mono C # compiler, The Mono instant compiler, And The mint (The Mono interpreter ). Now you can write C # program. For example, hey, write the most famous Hellow World Program:

Class Hello {
Static void Main (){
System. Console. WriteLine ("Hello World ");
}
}

Haha, it is really a classic. C # the program must be suffixed with. cs. Enter the program and save it. For example, save it as HelloWorld. cs and compile it:

# Mcs Hello. cs

If you write all programs, this command will generate a MSIL file named helloworld.exe, and then you can use this file:

# Mint HelloWorld.exe
Hello World

Mint interprter has many optional commands, including -- trace and -- debug, which are useful for debugging. When your program has been completed, you can compile it on the JIT compiler:

# Mono HelloWorld.exe

Hello World

The public Language Runtime Library provides cross-platform capabilities .. . NET program can run on any system with CLR installed. In fact, the C # compiler of Mono is compiled on the Windows platform using the Microsoft. NET Framework SDK and then moved to the Linux platform. You can convert the compiled program on Windows to Linux and run it.

Mono has not fully implemented the. NET Framework, but it is enough for you to run the program you want to write. Open-source things generally evolve quickly, and may soon be able to fully meet your needs.

By the way, there is a Gtk # project on the gtk-sharp.sourceforge.net, which is committed to binding gtk + toolkit to the C # language. It is also designed to provide libraries compatible with Windows. Forms under Mono. Of course, it is difficult to migrate from Windows to Linux. Let's keep an eye on its progress.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.