General Purpose Samples
Discover fundamental examples for common programming tasks and utilities.
using System;
public class Greeter {
public static void Main(string[] args) {
Console.WriteLine("Hello, MSDN Sample!");
}
}
Explore a curated list of code samples showcasing various Microsoft technologies and development patterns.
Discover fundamental examples for common programming tasks and utilities.
using System;
public class Greeter {
public static void Main(string[] args) {
Console.WriteLine("Hello, MSDN Sample!");
}
}
Examples demonstrating ASP.NET Core, Blazor, and front-end technologies.
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();
}
}
Explore samples for WPF, Windows Forms, and UWP applications.
// 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>
Code samples for .NET MAUI and Xamarin development.
// 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);
}
}
Learn how to integrate your applications with Azure services.
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");
}
}