Is knowledge of C# of any use in a Linux system?

78,265

Solution 1

Most likely you will stumble upon http://www.mono-project.com/

As the About Mono page says:

Mono, the open source development platform based on the .NET Framework, allows developers to build cross-platform applications with improved developer productivity. Mono’s .NET implementation is based on the ECMA standards for C# and the Common Language Infrastructure.

The supported platforms include Linux.

Solution 2

Yes, you can develop software on Ubuntu, that itself will run on Ubuntu, in C#. Both Mono and .NET Core support GNU/Linux systems like Ubuntu. (You can use them on other distros, too, like Debian, Raspbian, Fedora, CentOS, Arch, Gentoo, and so forth.) The Unity3D game engine also supports Ubuntu, as you probably know. Unity3D embeds Mono.

A number of packages for Ubuntu, installable with Ubuntu's package manager from officially community-supported software sources, are written in C# and use Mono. This includes the music player Banshee, the notetaking app Tomboy, the raster graphics editor Pinta, and the password manager KeePass (since version 2).

Most text editors, such as Gedit, Vim, and Emacs, have syntax highlighting for C#. MonoDevelop and Visual Studio Code are two popular integrated development environments that run on Ubuntu and support C# development.

Solution 3

  1. You can now develop server applications on Linux using C# (.NET Core framework), like you can use Java or Python. By server applications I mean web applications and web service (REST) applications mostly. This makes a perfect match with Linux containers (Docker/K8s) and clouds.
  2. You can develop desktop applications with C# using the Mono Framework (a .NET implementation) and GTK# (GtkSharp) toolkit (a wrapper of GTK). There are many projects developed on it. This framework have had some resistance by part of the Linux's community in the past. Some distributions and users didn't want Mono applications.
  3. You can develop games with the Unity Engine using C# on Linux. Unity Editor is experimental on Linux yet.

So, yes. Knowledge on C# can be very useful on Linux systems today.

Solution 4

You can now even do XAML based front end cross platform (Linux, Mac, Windows, Android, iOS, UWP) apps using .Net Core and a new project called Avalonia. Avalonia is in Beta, but works pretty well now. It is similar to WPF, but with some CSS like enhancements to styling.

I believe on Linux Avalonia targets Gtk currently, but they're wanting to move to something else. IT's mentioned in this video, but I personally couldn't understand what he said: https://www.youtube.com/watch?v=WESJUJWBLJ0

Solution 5

Linux provides its native APIs in the C programming language. A native Linux program uses these APIs to access files, I/O devices, sockets (networking), inter-process communications, threading, etc. To create a native Linux app you would write your app in C and then compile it with (most likely) GCC to end up with an executable. You can even go further and use GUI libraries in your program to add GUI (GTK and Qt are two popular ones) or use a packaging system to package your app (like .deb and .rpm files).

C#, F# and VB bring their own compiler (which normally produces IL code instead of machine code) and instead of directly using the Windows or Linux native APIs (both in C), they have their own wrappers around them. This means that there needs to be another extra layer between the compiled code and the OS. This extra layer has to read the IL code and translate that to the native Windows or Linux or macOS APIs. This extra layer can be .NET Framework, Mono or .NET Core (currently just .NET).

Now to answer the question "Is C# usable for Linux system programming?", in most cases yes.

The .NET has libraries for file handling, networking, threading and some I/O devices. Now for example, say you need to access Bluetooth in you app. .NET does not have any APIs for Bluetooth, so in such cases you have two options:

  1. Find the native API in C and call it in C#
  2. Search in NuGet to see if someone has already done it

Other examples would be WiFi Direct, Gamepad, CPU temperature, Battery Info, Camera, GPS, Laptop Sensors, etc. So for low-level apps you're on your own (this is the case even on Windows unless you go with UWP). For such apps on Linux, C or Python would be a way better choice.

If you want to add GUI to your app, .NET has GUI libraries but only for Windows. Mono on the other hand has bindings for GTK called GTK# but naturally GTK# would always be behind the GTK development (which is not a problem unless you want the latest features).

.NET 6 has another solution for cross-platform GUI. In .NET 6 you can create a Blazor app with C#, HTML and CSS and use Electron to create a desktop app from it (as of writing this, it's not ready yet).

To sum up:

Pros of C# on Linux

  • You'd use your existing skills
  • If you stick to .NET libraries your app would be portable to Windows and mac
  • You're dealing with a modern clean language instead of a 50-year-old one (hardcore C programmers may disagree :D)

Cons of C# on Linux

  • Many native APIs are not available
  • On paper native C code would be faster than framework-dependent C# code. Although it's possible to directly compile for Linux but we'd loose portability and with today's hardware users wouldn't feel the difference anyway.
  • Your hands are tighter for a GUI app
Share:
78,265

Related videos on Youtube

Jacob
Author by

Jacob

History I was born at 1998 in Czech Republic. Sadly at the age of 5, I was diagnosed with Asperger syndrome what explaining my poor social abilities. People like me are marked as "retards" and no one IT school wants accept me. I wanted to show them how terribly they were wrong in me, not only in me but in other people like myself. At the age of 12, I started working with a tool called Game Maker, and at the age of 15 I started to learn the C # programming language. When I was 16, I finished my first game that I could not publish due to the copyright of the music used in the game. In autumn 2017, I finished the first public game named War City. Character Mealchonic introver with a high level of intelligence but very weak social capabilities. I always liked anime and manga, I also like nightcore. I do not care what other people think about me and I will always do what I like, regardless of the opinion of others. I love old games, especially games for GameBoyAdvanced or PlayStation1 also I like games from the late DOS era and the early Windows era. These old games have something that is missing in the new games, something indescribable, something like.... soul.

Updated on September 18, 2022

Comments

  • Jacob
    Jacob over 1 year

    I know C# and I like to switch between systems and use Linux. Can I use C# to build applications that will natively work on Linux? What should I do to make use of my knowledge of C# in a Linux system?

    Note that I'm specialized in Unity3D, but I still want to create Linux applications using C#.

    • lamont
      lamont about 6 years
      KerbalSpaceProgram is written in Unity and runs on Win/Mac/Linux. Plugins/Mods to KSP are written in C# and can be developed on Win, Mac or Linux. I use primarily Mac now instead of Linux for $REASONS, but I do KSP mod development on that platform in C# and not windows. I'm likely going to write some stand-alone C# code with xUnit tests outside of KSP soon and it'll be just like any other development, but I'll just have to run it under mono. MechJeb has an example Makefile that builds on Mac+Linux: github.com/MuMech/MechJeb2/blob/master/Makefile (requires KSP game dlls to link).
    • OrangeDog
      OrangeDog about 6 years
      C# applications don't usually run natively anywhere.
    • Jacob
      Jacob about 6 years
      @OrangeDog I know, even on Windows you need to install .Net framework. If i said "natively" i mean without any emulation or compatibility layer. I basically mean if Linux support it no matter how many programs or packages you need to install.
    • underscore_d
      underscore_d about 6 years
      What relevance does any of this have to Ubuntu?
    • Jacob
      Jacob about 6 years
      @underscore_d Well, Ubuntu is linux system and i'm going to install it. I was worried my knowledge of C# become useless so i asked here.
    • Nic
      Nic about 6 years
      I'd like to answer somewhat tangentially that your C# experience will probably help you learn more *nix-specific tools like shell scripting. From experience, learning to code in one language helps you to learn others.
    • Jacob
      Jacob about 6 years
      @NicHartley Yeah, i know it pretty well because i learned C# on top of GML, a language useful only in tool GameMaker. But that is enough for me. If i go for more languages at once I will learn less of them all. That is why i want to focus on one language and master it to perfection. I choosed C# 4 years ago because i felt limited by GML, and GML itself is C-based language so switch to C# was not so difficult.
    • underscore_d
      underscore_d about 6 years
      I mean direct relevance, not vague/tangential relevance. This SE site exists for questions that are specifically about Ubuntu or at least influenced enough by its particular properties that it's relevant. I don't think Ubuntu has any special properties wrt C# that make this an on-topic question.
    • Jacob
      Jacob about 6 years
      @underscore_d Oh, i see. I thought some Ubuntu - specific steps must be done in order to create or run C# applications. Looks like here are no tasks specific to Ubuntu, yet. Let it be here, maybe someone come with something specific to Ubuntu.
    • Eliah Kagan
      Eliah Kagan about 6 years
      @underscore_d I don't know where you heard that, but it's not true. See Are “not only Ubuntu-specific” questions on-topic? Many, many questions on Ask Ubuntu apply equally to the vast majority of GNU/Linux systems. Maybe someone will find a plausible reason to consider this question off-topic, but if so, it won't be that. (Btw, this does have answers with Ubuntu-specific information. The second paragraph of my own post is about Ubuntu packages; it carries over to some, but not all, other distros.)
  • Jacob
    Jacob about 6 years
    Mono... sound familiar... Oh yeah, this is what is unity based on ! I had no idea that i can use it separately. I thought it is part of Unity3d.
  • Eliah Kagan
    Eliah Kagan about 6 years
    @Garrom It is also part of Unity3d; that game engine embeds Mono. But you can write standalone programs that run with Mono, too. (You can also write your own native code programs that embed Mono, as Unity3d does, if you should ever want to do that.)
  • Actually a physicist
    Actually a physicist about 6 years
    But is Mono up to date with Microsoft's latest implementation of .NET?
  • Eliah Kagan
    Eliah Kagan about 6 years
    @Actuallyaphysicist It depends what you need but pretty much, yes. There's a usually brief lag between new framework and C# and F# versions, and Mono support. IMHO the main missing thing in Mono is WPF. But it also doesn't have some libraries that are long-deprecated or highly Windows-specific. Note, however, that the version of Mono packaged downstream for your Ubuntu release may not have the latest functionality. So you may want to use the Mono Project repository.
  • Milan
    Milan about 6 years
    The latest version of Microsoft's implementation (.Net Core) also supports Linux.
  • casey
    casey about 6 years
    Mono implements .net standard 2.0 (iirc) not just core.
  • Wilbert
    Wilbert about 6 years
    Maybe also mention Rider, the intellij idea-based IDE for C# that contains all the functionality of ReSharper for Visual Studio.
  • Mr. Sam
    Mr. Sam about 6 years
    This would have been a nice answer a few years ago. Now it’s pretty much obsolete.
  • PmanAce
    PmanAce about 6 years
    You can also do desktop applications in .NET Core.
  • somebody
    somebody about 6 years
    @KonradRudolph obsolete? but doesn't .NET core basically require NuGet dependencies for basically any production-level program? or are there other alternatives
  • user2066657
    user2066657 about 6 years
    You may want to tune up this answer so it implies that other distributions of linux do exist. Since they will also provide or support mono, you may want to be a little more neutral and inclusive.
  • Eliah Kagan
    Eliah Kagan about 6 years
    @user2066657 Thanks for the suggestion; I've edited. I had meant to make clear how Mono and .NET Core were not limited to Ubuntu ("GNU/Linux systems like Ubuntu"). But on further consideration, I realize this may not have been clear to readers who didn't already know what I was trying to tell them. So I've expanded that part. I do realize this edit may not satisfy you: I've made it more inclusive, but not more neutral. It's reasonable for posts on this site to emphasize Ubuntu. The middle part, giving examples of C# programs with downstream Ubuntu packages, is deliberately focused on Ubuntu.
  • Mr Lister
    Mr Lister about 6 years
    If the OP had wanted to ask about non-Ubuntu OSes, they would probably have asked in Unix & Linux.
  • Eliah Kagan
    Eliah Kagan about 6 years
    @MrLister Yes, agreed. But I think something is gained, and nothing lost, by the clarification I have added. I don't plan to retool the post as a whole, though. For example, I considered saying something about which distros MonoDevelop and Visual Studio Code are reasonably easy to install and use on, but decided against doing so, on the grounds that it's somewhat complicated and would end up changing the tone and focus (and length!) of the post.
  • Farhan Anam
    Farhan Anam about 6 years
    @somebody Afaik it creates dependencies for the packages you actually use in the program. Contrary to the usual "include everything" principle of Mono/.NET Framework.
  • somebody
    somebody about 6 years
    @FarhanAnam it also doesn't include a lot of things
  • Lukazoid
    Lukazoid about 6 years
    If you are using a recent version of Ubuntu, please please please don't use mono, it has so many bugs and poor implementations, use .net core. Where I work, almost every issue we have when running C# applications on old linux distros can be explained with the statement: "because of mono". Exception filters losing stack traces, async implementations which are Task.Run wrappers, memory leaks all over the shot and lack of valgrind support so you can't even properly diagnose the leak.
  • NPSF3000
    NPSF3000 about 6 years
    @somebody "but doesn't .NET core basically require NuGet dependencies for basically any production-level program? " Yes, but that's got nothing to do with its readiness as a platform. It's more of a feature in that it's a far more modular framework... though time will tell.
  • somebody
    somebody about 6 years
    @NPSF3000 by that I mean thirt-party NuGet dependencies for things Microsoft should have provided (I think)
  • NPSF3000
    NPSF3000 about 6 years
    @somebody I haven't noticed it being any worse than normal C#... or you know, open source software...
  • Chris Bordeman
    Chris Bordeman about 6 years
    The Avalonia project also allows you to do XAML based front end development on all desktop and mobile platforms, too. On Linux it targets Gtk for now, though they want to change that.
  • Chris Bordeman
    Chris Bordeman over 4 years
    Just FYI, Unity uses .Net Core these days, NOT Mono (which is deprecated). Its new DOTS platform also uses a subset of C# features that removes the garbage collector and classes in favor of a Data Oriented programming paradigm that gives such extreme performance you have to see it to believe.
  • Chris Bordeman
    Chris Bordeman over 4 years
    You can even use Avalonia, an open source, cross platform reimplementation of WPF, to write Android/iOS/Linux/Mac/Windows apps these days. It's a much better option than Xamarin IMO. It's much more performant than WPF and has some nice improvements to it like CSS selectors in the styling system.
  • Chris Bordeman
    Chris Bordeman over 4 years
    You can also use Avalonia, a cross platform WPF re-implementation to do mobile+desktop apps on Mac+Linux+Windows. Finally a non-garbage UI toolkit!
  • Ray Wu
    Ray Wu about 3 years
    How does this answer the question in any way? I don't think anyone asked about P/Invoke
  • Chris Bordeman
    Chris Bordeman almost 3 years
    I'd say not supporting every conceivable OS API is SOP for any language, so don't put that in 'cons.' Otherwise great synopsis! And thanks for mentioning P/Invoke, since it is important to usefulness.