ASP.NET Core
Building Web APIs with Minimal APIs
Learn how to create efficient and lightweight web APIs using ASP.NET Core's Minimal API feature.
// Program.cs
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/", () => "Hello World!");
app.MapGet("/api/products", () => new List<object>
{
new { Id = 1, Name = "Laptop", Price = 1200.00 },
new { Id = 2, Name = "Keyboard", Price = 75.00 }
});
app.Run();
WPF
Data Binding with MVVM Pattern
Implement the Model-View-ViewModel (MVVM) pattern for robust WPF application design, focusing on effective data binding.
// ViewModel.cs
public class MyViewModel : INotifyPropertyChanged
{
private string _message;
public string Message
{
get => _message;
set
{
_message = value;
OnPropertyChanged(nameof(Message));
}
}
// ... INotifyPropertyChanged implementation ...
}
// MainWindow.xaml
<Window ...>
<Window.DataContext>
<local:MyViewModel />
</Window.DataContext>
<TextBlock Text="{Binding Message}" />
</Window>
Entity Framework Core
Code-First Approach to Database Development
Build your data model in code and let Entity Framework Core generate your database schema using the Code-First approach.
// DbContext.cs
public class BloggingContext : DbContext
{
public DbSet<Blog> Blogs { get; set; }
public DbSet<Post> Posts { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer("Server=(localdb)\\mssqllocaldb;Database=BloggingDB;Trusted_Connection=True;");
}
}
// Model.cs
public class Blog
{
public int BlogId { get; set; }
public string Url { get; set; }
public virtual ICollection<Post> Posts { get; set; }
}
Xamarin.Forms
Creating Cross-Platform Mobile UIs
Develop native mobile applications for iOS, Android, and Windows with a single shared C# codebase.
// MainPage.xaml
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MyMobileApp.MainPage">
<StackLayout Padding="20">
<Label Text="Welcome to Xamarin.Forms!"
VerticalOptions="Center"
HorizontalOptions="Center" />
<Button Text="Click Me" Clicked="OnButtonClicked" />
</StackLayout>
</ContentPage>
LINQ
Advanced Querying with LINQ
Master Language Integrated Query (LINQ) to perform powerful data manipulation and querying directly in your C# code.
// Sample data
var numbers = new List<int> { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
// Filter and sort even numbers greater than 3
var query = from num in numbers
where num % 2 == 0 && num > 3
orderby num
select num;
foreach (var number in query)
{
Console.WriteLine(number);
}
// Output: 4, 6, 8
.NET MAUI
Getting Started with .NET MAUI
Build native .NET applications for Windows, macOS, iOS, and Android from a single C# codebase with .NET MAUI.
// App.xaml.cs
public partial class App : Application
{
public App()
{
InitializeComponent();
MainPage = new NavigationPage(new Views.HomePage());
}
}
// HomePage.xaml
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MyMauiApp.Views.HomePage"
Title="Home">
<VerticalStackLayout Spacing="10" Padding="20">
<Label Text="Welcome to .NET MAUI!" />
<Button Text="Navigate" Clicked="OnNavigateClicked" />
</VerticalStackLayout>
</ContentPage>