Sample Code Collections

Explore a curated list of code samples showcasing various Microsoft technologies and development patterns.

General Purpose Samples

Discover fundamental examples for common programming tasks and utilities.

C# VB.NET Core Utilities
using System; public class Greeter { public static void Main(string[] args) { Console.WriteLine("Hello, MSDN Sample!"); } }

Web Development Showcase

Examples demonstrating ASP.NET Core, Blazor, and front-end technologies.

ASP.NET Core Blazor JavaScript React API
public class WeatherForecastController : Controller { private static readonly string[] Summaries = new[] { "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" }; [HttpGet] public IEnumerable<WeatherForecast> Get() { var rng = new Random(); return Enumerable.Range(1, 5).Select(index => new WeatherForecast { Date = DateTime.Now.AddDays(index), TemperatureC = rng.Next(-20, 55), Summary = Summaries[rng.Next(Summaries.Length)] }) .ToArray(); } }

Desktop Application Patterns

Explore samples for WPF, Windows Forms, and UWP applications.

WPF WinForms UWP MVVM UI
// XAML Example <Window x:Class="MyWpfApp.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="450" Width="800"> <Grid> <Button Content="Click Me" HorizontalAlignment="Center" VerticalAlignment="Center" Click="Button_Click"/> </Grid> </Window>

Mobile App Solutions

Code samples for .NET MAUI and Xamarin development.

MAUI Xamarin iOS Android Cross-Platform
// C# Example for .NET MAUI public partial class MainPage : ContentPage { public MainPage() { InitializeComponent(); } private void OnCounterClicked(object sender, EventArgs e) { count++; CounterBtn.Text = $"Clicked {count} time"; SemanticScreenReader.Announce(CounterBtn.Text); } }

Azure Cloud Integration

Learn how to integrate your applications with Azure services.

Azure Functions Azure SQL Azure Storage Cosmos DB Cloud
public static class AzureFunctionsExample { [FunctionName("HttpTriggerExample")] public static async Task<IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequest req, ILogger log) { log.LogInformation("C# HTTP trigger function processed a request."); string name = req.Query["name"]; string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); dynamic data = JsonConvert.DeserializeObject(requestBody); name = name ?? data?.name; return name != null ? (ActionResult)new OkObjectResult($"Hello, {name}") : new BadRequestObjectResult("Please pass a name on the query string or in the request body"); } }