C# is a modern object-oriented programming language from Microsoft, serving as the foundation for Xamarin and .NET MAUI platforms in mobile development. Thanks to the unified .NET ecosystem, developers can create mobile applications for iOS and Android using shared C# and XAML code. According to the TIOBE index (2026), C# ranks 4th in popularity among all programming languages. Learn more in Microsoft C# documentation.
Key takeaways
C# (pronounced "see sharp") is an object-oriented programming language with a safe type system, developed by Microsoft in 2000 under the leadership of Anders Hejlsberg. The name is inspired by musical notation (sharp — raising the pitch). C# runs on the .NET platform, which includes the Common Language Runtime (CLR) and an extensive class library (BCL — Base Class Library).
In mobile development, C# is used through two technologies: Xamarin (2011–2024) and its successor .NET MAUI (2022+). Xamarin enabled creating native Android and iOS applications with shared C# code, separating platform-specific projects. .NET MAUI combines all platforms into a single project with shared XAML markup and access to native APIs through platform interfaces.
A key feature of C# is strict static typing with the ability for dynamic dispatch through dynamic, the var keyword (type inference) and a powerful generics system. C# is a fully managed language: memory is managed by the garbage collector (GC), array bounds are checked, uninitialized variables are prohibited. This makes C# safer than C++ with comparable performance through AOT compilation.
C# 1.0 (2000) — basic OOP language. C# 3.0 (2007) — LINQ, lambda expressions, extension methods. C# 6.0 (2015) — string interpolation, null-conditional operator. C# 8.0 (2019) — nullable reference types (null safety enforcement), async streams, default interface methods. C# 10 (2021) — global usings, file-scoped namespaces, record struct. C# 12 (2023) — primary constructors, collection expressions, interceptors. Each version brings improvements relevant to mobile development.
| C# version | Year | Key feature | Relevance for mobile development |
|---|---|---|---|
| 3.0 | 2007 | LINQ, lambdas | Simplified work with collections and databases |
| 6.0 | 2015 | ?. (null-conditional), string interpolation | Safe property access, readable strings |
| 8.0 | 2019 | Nullable reference types, async streams | Null safety, asynchronous data streams |
| 10 | 2021 | Record struct, global usings | Value types, reduced boilerplate |
| 12 | 2023 | Primary constructors, collection expressions | Concise class and collection notation |
C# syntax is C-like, strictly typed. Everything is an object, including primitives (int, double, bool — these are structs inheriting ValueType). C# divides types into value types (int, double, bool, struct, enum — stored on the stack) and reference types (string, class, interface, delegate, array, record — stored on the heap). Nullable types (int?) allow null for value types.
C# supports classes (class), structs (struct), records (record), interfaces (interface), enums (enum) and delegates (delegate). record is an immutable reference type with value-based equality (two records are equal if all their fields are equal). record struct — value version of record, introduced in C# 10. primary constructors (C# 12) combine declaration and initialization into one line.
// Basic C# types and classes
using System;
using System.Collections.Generic;
// Record with primary constructor (C# 12)
public record User(int Id, string Name, string Email);
// Class with nullable properties
public class AppConfig
{
public string AppName { get; init; }
public string? ApiUrl { get; set; } // nullable reference type
public int Version { get; init; }
// Method with expression body
public string GetDisplayName() => $"{AppName} v{Version}";
}
// Extension method
public static class StringExtensions
{
public static bool IsValidEmail(this string email) =>
email.Contains("@") && email.Contains(".");
}
// Usage
var user = new User(1, "Alice", "alice@example.com");
bool validEmail = user.Email.IsValidEmail();Record User with primary constructor automatically generates equals, hashCode, ToString, Deconstruct and with-copying. init-only setters (AppName) allow setting a value only in the initializer. Expression body (=>) is a concise notation for simple methods. Extension method IsValidEmail adds a method to string without inheritance.
LINQ is a built-in query language for collections, databases, XML. LINQ to Objects — queries to IEnumerable collections. LINQ to SQL — to databases. LINQ to XML — to XML. Syntax can be query (from u in users where u.Age > 18 select u) and method (users.Where(u => u.Age > 18).Select(u => u)). Lazy loading (deferred execution): query executes upon iteration, not upon declaration.
// LINQ queries to collections
using System.Linq;
var users = new List<User>
{
new User(1, "Alice", "alice@example.com"),
new User(2, "Bob", "bob@test.com"),
new User(3, "Charlie", "charlie@example.com"),
};
// Query syntax
var filteredUsers = from u in users
where u.Email.Contains("example")
orderby u.Name
select u;
// Method syntax with multiple operations
var result = users
.Where(u => u.Email.Contains("example"))
.OrderBy(u => u.Name)
.Select(u => new { u.Name, u.Email })
.ToList();
// GroupBy and aggregation
var emailsByDomain = users
.GroupBy(u => u.Email.Split('@')[1])
.Select(g => new { Domain = g.Key, Count = g.Count() });
// LINQ with async stream (IAsyncEnumerable)
await foreach (var user in GetUsersAsync())
{
Console.WriteLine(user.Name);
}
async IAsyncEnumerable<User> GetUsersAsync()
{
yield return new User(1, "Alice", "alice@example.com");
await Task.Delay(100);
yield return new User(2, "Bob", "bob@test.com");
}LINQ query filteredUsers filters users by email domain and sorts by name. Method syntax .Where().OrderBy().Select() is a method chain equivalent to query syntax. GroupBy groups by email domain. IAsyncEnumerable (C# 8) is an async version of IEnumerable, useful for streaming data loading in mobile applications.
Xamarin (2011–2024) was Microsoft's first platform for cross-platform mobile development in C#. It consisted of Xamarin.Android (Mono runtime on top of Linux kernel) and Xamarin.iOS (AOT compilation to ARM64 due to JIT prohibition on iOS). Xamarin.Forms was a shared UI layer with XAML markup, translating elements to native (Android View / iOS UIView).
.NET MAUI (.NET Multi-platform App UI) is the successor to Xamarin, released in 2022. A single .csproj project, one XAML markup, one entry point. Supports 5 platforms: iOS, Android, Windows (WinUI 3), macOS (Mac Catalyst), Tizen. .NET MAUI uses the new Handler architecture instead of Renderer: each XAML element maps to a native component through a platform handler.
<!-- MainPage.xaml — declarative .NET MAUI UI -->
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MyApp.MainPage">
<ScrollView>
<VerticalStackLayout Padding="30" Spacing="25">
<Label Text="Welcome to .NET MAUI!"
FontSize="32"
HorizontalOptions="Center"/>
<Entry x:Name="NameEntry"
Placeholder="Enter your name"/>
<Button Text="Submit"
Clicked="OnSubmitClicked"
BackgroundColor="#512BD4"
TextColor="White"
CornerRadius="8"/>
<CollectionView x:Name="ItemsView"
SelectionMode="Single">
<CollectionView.ItemTemplate>
<DataTemplate>
<Grid Padding="10">
<Label Text="{Binding Name}"
FontSize="18"/>
</Grid>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</VerticalStackLayout>
</ScrollView>
</ContentPage>.NET MAUI XAML markup describes UI declaratively. ScrollView — scrolling, VerticalStackLayout — vertical arrangement. Label, Entry (text input), Button — basic elements. CollectionView — virtualized list with DataTemplate for displaying items. The Clicked event binds to the OnSubmitClicked method in the MainPage.xaml.cs code-behind.
// MainPage.xaml.cs — code-behind with C# logic
namespace MyApp;
public partial class MainPage : ContentPage
{
private readonly List<User> _users = new();
public MainPage()
{
InitializeComponent();
LoadUsers();
}
private async void OnSubmitClicked(object? sender, EventArgs e)
{
var name = NameEntry.Text?.Trim();
if (string.IsNullOrEmpty(name))
{
await DisplayAlert("Error", "Name is required", "OK");
return;
}
_users.Add(new User(_users.Count + 1, name, $"{name}@example.com"));
ItemsView.ItemsSource = null;
ItemsView.ItemsSource = _users;
NameEntry.Text = string.Empty;
}
private async void LoadUsers()
{
var apiService = new ApiService();
var users = await apiService.GetUsersAsync();
_users.AddRange(users);
ItemsView.ItemsSource = _users;
}
}Code-behind MainPage inherits ContentPage. InitializeComponent() loads XAML markup. NameEntry.Text?.Trim() — null-conditional operator (?.) for safe access. DisplayAlert — native dialog. ItemsView.ItemsSource — Binding to collection. async/await for asynchronous loading. MVVM (Model-View-ViewModel) pattern is recommended for complex projects.
C# mobile development offers three approaches: .NET MAUI (cross-platform UI), Xamarin (legacy) and Unity (games). .NET MAUI is the recommended path for new projects. C# application compiles to Intermediate Language (IL), which NativeAOT (.NET MAUI) or Mono (Xamarin) transforms into native ARM code. iOS requires AOT compilation — JIT is prohibited by Apple policies.
.NET MAUI provides unified APIs for working with platform capabilities through interfaces: IAccelerometer, IBarometer, IBattery, IConnectivity, IDeviceInfo, IFilePicker, IGeolocation, IMediaPicker, IPermissions, ISpeechRecognizer, IVibration. For platform-specific code, Conditional compilation (#if ANDROID, #if IOS) or partial class is used.
// Geolocation in .NET MAUI with DI
public class LocationService
{
private readonly IGeolocation _geolocation;
public LocationService(IGeolocation geolocation)
{
_geolocation = geolocation;
}
public async Task<Location?> GetCurrentLocation()
{
try
{
var permission = await CheckAndRequestPermission();
if (permission != PermissionStatus.Granted)
return null;
var location = await _geolocation.GetLastKnownLocationAsync();
if (location == null)
{
location = await _geolocation.GetLocationAsync(new GeolocationRequest
{
DesiredAccuracy = GeolocationAccuracy.Medium,
Timeout = TimeSpan.FromSeconds(10)
});
}
return location;
}
catch (Exception ex)
{
Debug.WriteLine($"Location error: {ex.Message}");
return null;
}
}
private async Task<PermissionStatus> CheckAndRequestPermission()
{
var status = await Permissions.CheckStatusAsync<Permissions.LocationWhenInUse>();
if (status != PermissionStatus.Granted)
{
status = await Permissions.RequestAsync<Permissions.LocationWhenInUse>();
}
return status;
}
}LocationService uses DI (dependency injection of IGeolocation). CheckAndRequestPermission checks and requests geolocation permission. GetLastKnownLocationAsync — fast (but not always accurate) response, GetLocationAsync — request with accuracy and timeout parameters. null-checks (location == null) with nullable reference types. try-catch handles platform exceptions.
C# on mobile devices shows performance comparable to Java/Kotlin on Android and Swift on iOS. NativeAOT (.NET 8+) compiles C# directly to native code without an IL intermediate stage — this reduces startup time by 50% and lowers memory consumption. GC in .NET MAUI is optimized for mobile platforms with short pauses (Workstation GC). APK size is ~20-30 MB (with NativeAOT).
| Parameter | Xamarin | .NET MAUI |
|---|---|---|
| Architecture | Xamarin.Android + Xamarin.iOS | Single .csproj project |
| UI rendering | Renderer (Xamarin.Forms) | Handler (.NET MAUI) |
| Compilation | Mono JIT (Android), AOT (iOS) | NativeAOT (all platforms) |
| Status | Maintenance mode | Active development |
| Platforms | Android, iOS, Windows | Android, iOS, Windows, macOS, Tizen |
.NET platform is an ecosystem for executing managed code, including CLR (Common Language Runtime), BCL (Base Class Library), ASP.NET Core for server development and .NET MAUI for mobile applications. .NET 8+ is a unified platform for all application types: mobile, desktop, web, cloud, IoT, games (Unity).
CLR is a virtual machine that executes CIL (Common Intermediate Language) code. C#, VB.NET, F# compile to CIL. The CLR JIT compiler transforms CIL into machine code upon the first method call. NativeAOT (ahead-of-time compilation) compiles CIL into native code at build time — ideal for mobile platforms where JIT may be restricted (iOS).
GC .NET garbage collector is generational (generations 0, 1, 2), automatically frees unused objects. Workstation GC with minimal pauses is recommended for mobile applications. GC runs in a separate thread, not blocking the UI thread. Background GC is a background collector minimizing pauses for interactive applications.
C# developer tools include Visual Studio, .NET SDK, dotnet CLI, NuGet, JetBrains Rider. Visual Studio 2022 is the main IDE with XAML designer, managed and native code debugger, CPU/memory profiler. .NET SDK includes csc compiler, dotnet CLI (dotnet new, dotnet build, dotnet publish, dotnet test).
NuGet is the .NET package manager, similar to npm for JS. 300,000+ packages, including CommunityToolkit.Maui (UI components), SQLite-net (database), Firebase Cloud Messaging, ZXing.Net.Maui (QR codes). .NET MAUI Community Toolkit is a set of behaviors, converters, animations for faster development. RestSharp and Refit are HTTP clients. Prism and MVVM Community Toolkit are architectural frameworks.
<!-- .csproj — .NET MAUI project configuration -->
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0-android;net8.0-ios;net8.0-maccatalyst</TargetFrameworks>
<OutputType>Exe</OutputType>
<UseMaui>true</UseMaui>
<ApplicationTitle>MyMAUIApp</ApplicationTitle>
<ApplicationId>com.example.mymauiapp</ApplicationId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Maui" Version="9.0.0" />
<PackageReference Include="sqlite-net-pcl" Version="1.9.172" />
<PackageReference Include="Refit" Version="7.0.0" />
</ItemGroup>
</Project>The .csproj file is the .NET MAUI project configuration. TargetFrameworks lists target platforms. UseMaui enables the MAUI SDK. PackageReference specifies NuGet dependencies. CommunityToolkit.Maui provides UI components (toasts, snackbars, Popup). sqlite-net-pcl is a local database. Refit is a typed HTTP client based on interfaces. dotnet build/publish builds the application for all platforms.
Frequently asked questions
C# is an object-oriented programming language from Microsoft (2000), running on the .NET platform (CLR). Used for mobile development through Xamarin and .NET MAUI. Combines strict static typing, automatic memory management (GC), LINQ, async/await and generics. Ranks 4th in the TIOBE index (2026). Developed by Anders Hejlsberg.
Xamarin was the predecessor (2011-2024), separating projects into Xamarin.Android and Xamarin.iOS. .NET MAUI (2022+) is a single .csproj project with shared XAML markup, Handler architecture instead of Renderer and support for 5 platforms (iOS, Android, Windows, macOS, Tizen). Xamarin has entered maintenance mode, new projects are built on .NET MAUI. NativeAOT is only available in .NET MAUI.
C# compiles to CIL (Common Intermediate Language), which NativeAOT (.NET MAUI) or Mono (Xamarin) transforms into native ARM code. Android uses Mono runtime (Xamarin) or NativeAOT (.NET MAUI) to execute IL. iOS requires AOT compilation — JIT is prohibited by Apple. .NET MAUI provides unified APIs for camera, GPS, sensors with platform implementation through interfaces.
C# divides types into value types (int, double, bool, char, struct, enum — stack) and reference types (string, class, interface, array, delegate, record — heap). Nullable types (int?) allow null for value types. record (C# 9) is an immutable reference type with value-based equality. record struct (C# 10) is a value version. dynamic — dynamic typing. var — compiler type inference.
Visual Studio 2022 (Windows) and Visual Studio for Mac are the main IDEs with XAML designer, debugger and profiler. .NET SDK — csc compiler, dotnet CLI, MSBuild. NuGet — package manager (300,000+). CommunityToolkit.Maui — UI components. JetBrains Rider — alternative IDE. Testing: xUnit, NUnit, Moq. CI/CD: Azure DevOps, GitHub Actions.
Summary
We will develop a mobile application turnkey
IT Sectr creates iOS and Android applications for startups and businesses since 2017. We will advise you and propose the best solution.
Read also