C# — isang makabagong object-oriented programming language mula sa Microsoft, na siyang pundasyon para sa Xamarin at .NET MAUI sa mobile development. Dahil sa nagkakaisang .NET ecosystem, ang mga developer ay maaaring lumikha ng mga mobile app para sa iOS at Android gamit ang shared code sa C# at XAML. Ayon sa TIOBE index (2026), ang C# ay nasa ika-4 na pwesto sa popularidad sa lahat ng programming language. Higit pa sa dokumentasyon ng Microsoft C#.
Mga Pangunahing Punto
C# (binibigkas na «si sharp») — isang object-oriented programming language na may ligtas na sistema ng uri, na binuo ng Microsoft noong 2000 sa pamumuno ni Anders Hejlsberg. Ang pangalan ay inspirasyon ng musical notation (sharp — pagtaas ng tono). Ang C# ay tumatakbo sa .NET platform, na kinabibilangan ng Common Language Runtime (CLR) at malawak na library ng klase (BCL — Base Class Library).
Sa mobile development, ang C# ay ginagamit sa pamamagitan ng dalawang teknolohiya: Xamarin (2011–2024) at ang kapalit nito na .NET MAUI (2022+). Pinahintulutan ng Xamarin ang paglikha ng native na Android at iOS app na may shared C# code, na naghihiwalay sa mga platform project. Pinagsasama ng .NET MAUI ang lahat ng platform sa iisang proyekto na may karaniwang XAML markup at access sa native API sa pamamagitan ng mga platform interface.
Pangunahing tampok ng C# — mahigpit na static typing na may kakayahang dynamic dispatch sa pamamagitan ng dynamic, keyword na var (type inference) at malakas na sistema ng generics. Ang C# ay isang fully managed language: ang memory ay pinamamahalaan ng garbage collector (GC), ang mga hangganan ng array ay sinusuri, ang mga hindi na-initialize na variable ay ipinagbabawal. Ginagawa nitong mas ligtas ang C# kaysa sa C++ na may maihahambing na pagganap sa pamamagitan ng AOT compilation.
C# 1.0 (2000) — pangunahing 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 (pag-activate ng null safety), async streams, default interface methods. C# 10 (2021) — global usings, file-scoped namespaces, record struct. C# 12 (2023) — primary constructors, collection expressions, interceptors. Bawat bersyon ay nagdadala ng mga pagpapabuti na may kaugnayan sa mobile development.
| Bersyon ng C# | Taon | Pangunahing Tampok | Kahalagahan para sa Mobile Development |
|---|---|---|---|
| 3.0 | 2007 | LINQ, lambda | Pinadaling trabaho sa mga koleksyon at database |
| 6.0 | 2015 | ?. (null-conditional), string interpolation | Ligtas na access sa mga property, nababasang string |
| 8.0 | 2019 | Nullable reference types, async streams | Null safety, asynchronous na daloy ng data |
| 10 | 2021 | Record struct, global usings | Mga value type, pagbawas ng boilerplate |
| 12 | 2023 | Primary constructors, collection expressions | Maikling pagsulat ng mga klase at koleksyon |
Sintaks ng C# — katulad ng C, mahigpit na naka-type. Lahat ay bagay, kasama ang mga primitive (int, double, bool — ito ay mga struct na nagmamana ng ValueType). Hinahati ng C# ang mga uri sa value types (int, double, bool, struct, enum — nakaimbak sa stack) at reference types (string, class, interface, delegate, array, record — nakaimbak sa heap). Ang mga nullable na uri (int?) ay nagpapahintulot ng null para sa value types.
C# ay sumusuporta sa mga klase (class), struktura (struct), record (record), interface (interface), enumeration (enum) at delegate (delegate). record — isang hindi nababagong reference type na may value-based equality (ang dalawang record ay pantay kung ang lahat ng kanilang field ay pantay). record struct — value na bersyon ng record, ipinakilala sa C# 10. primary constructors (C# 12) ay pinagsasama ang deklarasyon at initialisasyon sa isang linya.
// Mga pangunahing uri at klase ng C#
using System;
using System.Collections.Generic;
// Record na may primary constructor (C# 12)
public record User(int Id, string Name, string Email);
// Klase na may nullable na property
public class AppConfig
{
public string AppName { get; init; }
public string? ApiUrl { get; set; } // nullable reference type
public int Version { get; init; }
// Pamamaraan na may 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(".");
}
// Paggamit
var user = new User(1, "Alice", "alice@example.com");
bool validEmail = user.Email.IsValidEmail();Record User na may primary constructor ay awtomatikong bumubuo ng equals, hashCode, ToString, Deconstruct at with-copy. Ang init-only setters (AppName) ay nagpapahintulot na itakda ang halaga lamang sa initializer. Expression body (=>) — maikling pagsulat para sa simpleng mga pamamaraan. Ang extension method na IsValidEmail ay nagdaragdag ng pamamaraan sa string nang walang inheritance.
LINQ — built-in na query language para sa mga koleksyon, database, XML. LINQ to Objects — mga query sa IEnumerable koleksyon. LINQ to SQL — sa database. LINQ to XML — sa XML. Ang sintaks ay maaaring query (from u in users where u.Age > 18 select u) at method (users.Where(u => u.Age > 18).Select(u => u)). Lazy loading (deferred execution): ang query ay isinasagawa sa iteration, hindi sa deklarasyon.
// LINQ query sa mga koleksyon
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 na may maraming operasyon
var result = users
.Where(u => u.Email.Contains("example"))
.OrderBy(u => u.Name)
.Select(u => new { u.Name, u.Email })
.ToList();
// GroupBy at aggregation
var emailsByDomain = users
.GroupBy(u => u.Email.Split('@')[1])
.Select(g => new { Domain = g.Key, Count = g.Count() });
// LINQ na may 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 ay nagsasala ng mga user ayon sa email domain at nag-uuri ayon sa pangalan. Method syntax .Where().OrderBy().Select() — chain ng mga pamamaraan, katumbas ng query syntax. Ang GroupBy ay nag-grupo ayon sa email domain. IAsyncEnumerable (C# 8) — asynchronous na bersyon ng IEnumerable, kapaki-pakinabang para sa streaming ng data sa isang mobile app.
Xamarin (2011–2024) — unang platform ng Microsoft para sa cross-platform mobile development sa C#. Binubuo ito ng Xamarin.Android (Mono runtime sa ibabaw ng Linux kernel) at Xamarin.iOS (AOT compilation sa ARM64 dahil sa pagbabawal ng JIT sa iOS). Xamarin.Forms — karaniwang UI layer na may XAML markup, nagsasalin ng mga elemento sa native (Android View / iOS UIView).
.NET MAUI (.NET Multi-platform App UI) — kapalit ng Xamarin, inilabas noong 2022. Iisang .csproj project, isang XAML markup, isang entry point. Sumusuporta sa 5 platform: iOS, Android, Windows (WinUI 3), macOS (Mac Catalyst), Tizen. Gumagamit ang .NET MAUI ng bagong Handler architecture sa halip na Renderer: bawat XAML element ay naka-map sa isang native component sa pamamagitan ng platform handler.
<!-- MainPage.xaml — deklaratibong UI .NET MAUI -->
<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>XAML markup ng .NET MAUI ay naglalarawan ng UI nang deklaratibo. ScrollView — pag-scroll, VerticalStackLayout — vertical na layout. Label, Entry (input ng teksto), Button — pangunahing elemento. CollectionView — virtualized na listahan na may DataTemplate para sa pagpapakita ng mga elemento. Ang event na Clicked ay nakatali sa pamamaraang OnSubmitClicked sa code-behind ng MainPage.xaml.cs.
// MainPage.xaml.cs — code-behind na may 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 ay nagmamana ng ContentPage. Ini-load ng InitializeComponent() ang XAML markup. NameEntry.Text?.Trim() — null-conditional operator (?.) para sa ligtas na access. DisplayAlert — native na dialog. ItemsView.ItemsSource — Binding sa koleksyon. async/await para sa asynchronous na pag-load. Ang MVVM (Model-View-ViewModel) architecture ay inirerekomenda para sa mga kumplikadong proyekto.
C# mobile development ay nag-aalok ng tatlong approach: .NET MAUI (cross-platform UI), Xamarin (legacy) at Unity (mga laro). .NET MAUI — inirerekomendang landas para sa mga bagong proyekto. Ang C# app ay naka-compile sa Intermediate Language (IL), na ginagawang native ARM code ng NativeAOT (.NET MAUI) o Mono (Xamarin). Ang iOS ay nangangailangan ng AOT compilation — ang JIT ay ipinagbabawal ng patakaran ng Apple.
.NET MAUI ay nagbibigay ng pinag-isang API para sa pagtatrabaho sa mga kakayahan ng platform sa pamamagitan ng mga interface: IAccelerometer, IBarometer, IBattery, IConnectivity, IDeviceInfo, IFilePicker, IGeolocation, IMediaPicker, IPermissions, ISpeechRecognizer, IVibration. Para sa platform-specific code, ginagamit ang conditional compilation (#if ANDROID, #if IOS) o partial class.
// Geolokasyon sa .NET MAUI na may 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($"Error sa lokasyon: {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;
}
}Serbisyong LocationService ay gumagamit ng DI (dependency injection ng IGeolocation). Sinusuri at hinihiling ng CheckAndRequestPermission ang pahintulot ng geolocation. GetLastKnownLocationAsync — mabilis (ngunit hindi palaging tumpak) na tugon, GetLocationAsync — query na may mga parameter ng katumpakan at timeout. Mga pagsusuri ng null (location == null) na may nullable reference types. Ang try-catch ay humahawak ng mga exception ng platform.
C# sa mga mobile device ay nagpapakita ng pagganap na maihahambing sa Java/Kotlin sa Android at Swift sa iOS. Ang NativeAOT (.NET 8+) ay nagko-compile ng C# nang direkta sa native code nang walang IL intermediate stage — binabawasan nito ang oras ng startup ng 50% at nagpapababa ng konsumo ng memory. Ang GC sa .NET MAUI ay na-optimize para sa mga mobile platform na may maiikling pause (Workstation GC). Laki ng APK — ~20-30 MB (na may NativeAOT).
| Parameter | Xamarin | .NET MAUI |
|---|---|---|
| Arkitektura | Xamarin.Android + Xamarin.iOS | Iisang .csproj project |
| UI rendering | Renderer (Xamarin.Forms) | Handler (.NET MAUI) |
| Compilation | Mono JIT (Android), AOT (iOS) | NativeAOT (lahat ng platform) |
| Status | Mode ng suporta | Aktibong pag-develop |
| Platform | Android, iOS, Windows | Android, iOS, Windows, macOS, Tizen |
.NET platform — ecosystem para sa pag-execute ng managed code, kasama ang CLR (Common Language Runtime), BCL (Base Class Library), ASP.NET Core para sa server development at .NET MAUI para sa mga mobile app. .NET 8+ — pinag-isang platform para sa lahat ng uri ng app: mobile, desktop, web, cloud, IoT, Games (Unity).
CLR — virtual machine na nag-execute ng CIL (Common Intermediate Language) code. C#, VB.NET, F# ay naka-compile sa CIL. Ang JIT compiler ng CLR ay nagko-convert ng CIL sa machine code sa unang tawag ng pamamaraan. NativeAOT (pre-compilation) ay nagko-compile ng CIL sa native code sa yugto ng build — perpekto para sa mga mobile platform kung saan ang JIT ay maaaring limitado (iOS).
Garbage collector GC ng .NET — generational (mga henerasyon 0, 1, 2), awtomatikong nagpapalaya ng mga hindi ginagamit na bagay. Para sa mga mobile app, inirerekomenda ang Workstation GC na may kaunting pause. Ang GC ay nangyayari sa isang hiwalay na thread, hindi hinaharangan ang UI thread. Background GC — background collector na nagpapaliit ng mga pause para sa interactive na app.
Mga tool ng C# developer ay kinabibilangan ng Visual Studio, .NET SDK, dotnet CLI, NuGet, JetBrains Rider. Visual Studio 2022 — pangunahing IDE na may XAML designer, debugger para sa managed at native code, CPU/memory profiler. Kasama sa .NET SDK ang csc compiler, dotnet CLI (dotnet new, dotnet build, dotnet publish, dotnet test).
NuGet — .NET package manager, kahalintulad ng npm para sa JS. 300.000+ package, kasama ang CommunityToolkit.Maui (mga UI component), SQLite-net (database), Firebase Cloud Messaging, ZXing.Net.Maui (QR code). .NET MAUI Community Toolkit — koleksyon ng mga behavior, converter, animation para mapabilis ang development. RestSharp at Refit — HTTP client. Prism at MVVM Community Toolkit — architectural frameworks.
<!-- .csproj — configuration ng .NET MAUI project -->
<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>File na .csproj — configuration ng .NET MAUI project. Ang TargetFrameworks ay naglilista ng mga target na platform. Ang UseMaui ay nag-activate ng MAUI SDK. PackageReference — mga dependency mula sa NuGet. CommunityToolkit.Maui — mga UI component (toast, snackbar, Popup). sqlite-net-pcl — lokal na database. Refit — typed HTTP client batay sa mga interface. Ang dotnet build/publish ay bumubuo ng app para sa lahat ng platform.
Mga Madalas Itanong
C# — isang object-oriented programming language mula sa Microsoft (2000), na tumatakbo sa .NET (CLR) platform. Ginagamit para sa mobile development sa pamamagitan ng Xamarin at .NET MAUI. Pinagsasama ang mahigpit na static typing, automatic memory management (GC), LINQ, async/await at generics. Nasa ika-4 na pwesto sa TIOBE index (2026). Binuo ni Anders Hejlsberg.
Xamarin — nauna (2011-2024), hinati ang mga proyekto sa Xamarin.Android at Xamarin.iOS. .NET MAUI (2022+) — iisang .csproj project na may karaniwang XAML markup, Handler architecture sa halip na Renderer at suporta para sa 5 platform (iOS, Android, Windows, macOS, Tizen). Ang Xamarin ay lumipat sa support mode, ang mga bagong proyekto ay ginagawa sa .NET MAUI. Ang NativeAOT ay magagamit lamang sa .NET MAUI.
C# ay naka-compile sa CIL (Common Intermediate Language), na ginagawang native ARM code ng NativeAOT (.NET MAUI) o Mono (Xamarin). Ang Android ay gumagamit ng Mono runtime (Xamarin) o NativeAOT (.NET MAUI) para i-execute ang IL. Ang iOS ay nangangailangan ng AOT compilation — ang JIT ay ipinagbabawal ng Apple. Ang .NET MAUI ay nagbibigay ng pinag-isang API para sa camera, GPS, sensor na may platform implementation sa pamamagitan ng mga interface.
C# ay hinahati ang mga uri sa value types (int, double, bool, char, struct, enum — stack) at reference types (string, class, interface, array, delegate, record — heap). Ang mga nullable na uri (int?) ay nagpapahintulot ng null para sa value types. record (C# 9) — hindi nababagong reference type na may value-based equality. record struct (C# 10) — value na bersyon. dynamic — dynamic typing. var — type inference ng compiler.
Visual Studio 2022 (Windows) at Visual Studio for Mac — pangunahing IDE na may XAML designer, debugger at profiler. .NET SDK — csc compiler, dotnet CLI, MSBuild. NuGet — package manager (300.000+). CommunityToolkit.Maui — mga UI component. JetBrains Rider — alternatibong IDE. Para sa testing: xUnit, NUnit, Moq. Para sa CI/CD: Azure DevOps, GitHub Actions.
Buod
Gagawa kami ng mobile application na turnkey
Gumagawa ang IT Sectr ng mga iOS at Android application para sa mga startup at negosyo mula noong 2017. Magpapayo kami sa iyo at magmumungkahi ng pinakamahusay na solusyon.
Basahin din