C# Everywhere: How to Write Cross-Platform Applications Without Pain

Online Python Trainer for Beginners

Learn Python easily without overwhelming theory. Solve practical tasks with automatic checking, get hints in Russian, and write code directly in your browser — no installation required.

Start Course

Why C# is Not Just About Windows?

\n\n

For a long time, C# was associated exclusively with the Microsoft and Windows ecosystem. Developers who wanted to write for Linux or macOS looked towards Java, Python, or JavaScript. But times have changed. With the release of .NET Core (and then .NET 5/6/7/8), Microsoft made a decisive step into the world of open source and cross-platform development.

\n\n

Today, C# is a powerful, modern language that can be used to create everything: from console utilities for a Linux server to mobile applications for iOS and Android. All with one language, one IDE (Rider or VS Code), and, importantly, with a unified business logic codebase.

\n\n

In this article, we will break down which technologies allow you to write cross-platform applications in C#, compare them, show real code, and give practical advice. If you think C# is "only for Windows," get ready to be surprised.

\n\n

The Evolution of Cross-Platform in .NET

\n\n

C#'s path to cross-platform was long. Let's recall the main milestones:

\n\n
    \n
  • Mono (2004) — the first open-source implementation of .NET Framework for Linux. It worked, but with limitations.
  • \n
  • Xamarin (2011) — allowed writing mobile applications in C# for iOS and Android. A real breakthrough.
  • \n
  • .NET Core (2016) — a completely rewritten, modular, cross-platform framework. Open source.
  • \n
  • .NET 5+ (2020) — unification of all branches: .NET Framework, .NET Core, and Xamarin merged into a single .NET.
  • \n
  • .NET MAUI (2022) — the evolution of Xamarin.Forms for creating native UIs for all platforms.
  • \n
\n\n

Now, in 2024, we have a mature toolkit for developing for any platform. Let's look at the main options.

\n\n

Main Technologies for Cross-Platform Development in C#

\n\n

The choice of technology depends on what exactly you are writing. We will highlight four main directions:

\n\n

1. .NET MAUI — Native Mobile and Desktop Applications

\n\n

.NET MAUI (Multi-platform App UI) is a framework for creating user interfaces that work on Android, iOS, macOS, Windows, and (experimentally) Linux. You write XAML markup and C# logic once, and you get native applications as output.

\n\n

Code Example: A Simple Counter Application

\n\n
<!-- MainPage.xaml -->\n<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"\n             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"\n             x:Class="MauiApp1.MainPage">\n    <VerticalStackLayout Padding="30" Spacing="25">\n        <Label Text="Hello, Cross-Platform!"\n               FontSize="32"\n               HorizontalOptions="Center"/>\n        <Label x:Name="CounterLabel"\n               Text="0"\n               FontSize="48"\n               HorizontalOptions="Center"/>\n        <Button Text="Click Me"\n                Clicked="OnCounterClicked"\n                HorizontalOptions="Center"/>\n    </VerticalStackLayout>\n</ContentPage>
\n\n
// MainPage.xaml.cs\nnamespace MauiApp1;\n\npublic partial class MainPage : ContentPage\n{\n    private int _count = 0;\n\n    public MainPage()\n    {\n        InitializeComponent();\n    }\n\n    private void OnCounterClicked(object sender, EventArgs e)\n    {\n        _count++;\n        CounterLabel.Text = _count.ToString();\n    }\n}
\n\n

This code will work without changes on an iPhone, Android smartphone, MacBook, and Windows PC. For Linux, additional configuration is required, but the community is actively working on it.

\n\n

2. Avalonia UI — Desktop for Windows, Linux, and macOS with Unique Design

\n\n

Avalonia is an open-source framework inspired by WPF, but fully cross-platform. Its main feature: it does not emulate native controls, but draws its own interface via SkiaSharp. This gives full

Blogs

Book Recommendations