Small, runnable C#/.NET projects that each demonstrate one practical pattern: Azure Functions, dependency injection, async concurrency, SQL Server writes, Windows Forms, terminal UI, and AI integration.
This repository is a hands-on collection of C# code examples for .NET 6, .NET 8, and .NET 10. Each project is intentionally small and focused on one concept, so you can read the code, run it, and reuse the pattern in your own application.
Topics include Azure Functions isolated worker middleware, Durable Functions orchestration, keyed dependency injection, MediatR / CQRS, SemaphoreSlim throttling, Task.WhenAll exception handling, SQL Server bulk copy and table-valued parameter upserts, FakeLogger unit testing, JSONPath queries, Unsafe.As, Spectre.Console, Python.NET interop, and Azure OpenAI chat completion.
Use the project table to choose an example, then follow that folder's README for setup, configuration and known limitations.
| Project | Focus | What it demonstrates | Target |
|---|---|---|---|
| Durable | Azure Durable Functions | Stateful, chained orchestration pipelines in the isolated worker model | .NET 8 |
| Fake | Logging + unit testing | Testing ILogger code with FakeLogger<T> from Microsoft.Extensions.Diagnostics.Testing and MSTest |
.NET 8 |
| FourKWinForm | Windows Forms | High-DPI (SystemAware) desktop form |
.NET 8 |
| JsonSearchPatterns | JSON processing | Nine JSONPath query patterns with Newtonsoft.Json SelectTokens |
.NET 6 |
| KeyedService | Dependency injection | Keyed scoped services (AddKeyedScoped, [FromKeyedServices]) in Azure Functions |
.NET 8 |
| Mediat | CQRS + MediatR | Multi-layer Azure Functions solution with commands, queries, and pipeline behaviours | .NET 8 |
| Middleware | Azure Functions | IFunctionsWorkerMiddleware request transformation and exception handling |
.NET 6 / .NET 8 |
| PublicIP | Networking | Fetching the public IP address from the ipify API with HttpClient |
.NET 6 |
| PythonBridge | Interop | Calling Python from C# with Python.NET (pythonnet) |
.NET 8 |
| SemaphoreSlim | Concurrency | Limiting concurrent async downloads with SemaphoreSlim |
.NET 8 |
| Simple_ChatCompletion | AI integration | Azure OpenAI chat completion via the Azure.AI.OpenAI package and via raw REST |
.NET 8 |
| SpectreDemo | Terminal UI | Live panels, multi-task progress bars, and prompts with Spectre.Console | .NET 8 |
| SQLWrites | SQL Server | Three upsert strategies — per-row transactions, table-valued parameters, and bulk copy — with retry and optimistic concurrency | .NET 10 |
| TaskErrors | Async error handling | Capturing all exceptions from Task.WhenAll, not just the first |
.NET 8 |
| UnsafeAs | Low-level .NET | Zero-copy reinterpretation with Unsafe.As<TFrom, TTo> and unsafe pointers |
.NET 8 |
Every project folder has its own readme with detailed explanations, configuration, and sample requests.
Durable— Durable Functions orchestration and function chaining (isolated worker, Functions v4)KeyedService— keyed dependency injection with Azure FunctionsMediat— CQRS and MediatR flow in Azure FunctionsMiddleware— Azure Functions middleware examples for .NET 6 and .NET 8
SemaphoreSlim— throttling concurrent async workTaskErrors— understanding exceptions in async workflowsUnsafeAs— unsafe conversions and pointer-based operationsJsonSearchPatterns— practical JSONPath traversal and filtering
SQLWrites— SQL Server upsert strategies compared (normal, TVP, bulk)PythonBridge— bridging C# with PythonSimple_ChatCompletion— Azure OpenAI chat completion examples
FourKWinForm— Windows Forms app with DPI awarenessSpectreDemo— polished terminal demos using Spectre.Console
- C# / .NET 6, .NET 8, .NET 10
- Azure Functions v4 (isolated worker) and Durable Functions
- SQL Server (
Microsoft.Data.SqlClient) - MediatR
- Python.NET (
pythonnet) - Azure OpenAI (
Azure.AI.OpenAI) - Spectre.Console
- Newtonsoft.Json
- MSTest and
Microsoft.Extensions.Diagnostics.Testing - Windows Forms
Each project is self-contained. Install the .NET SDK version that the project targets (see the table above), pick one folder, and run it from there:
git clone https://github.com/gcfernando/csharp_codes.git
cd csharp_codes
# Example: run a single console project
cd SpectreDemo
dotnet runEvery project includes a Visual Studio solution (.sln) file. Folders that contain several projects (for example SQLWrites, Mediat, and Fake) need you to choose which project to run — open the solution in Visual Studio, or pass the project path from the repository root, for example:
dotnet run --project SQLWrites/UseNormalThe Azure Functions samples (Durable, KeyedService, Mediat, Middleware) require Azure Functions Core Tools and are started from the function project folder with:
func startSome samples need external resources — for example a SQL Server database (SQLWrites), an Azure OpenAI endpoint and key (Simple_ChatCompletion), or a local Python installation (PythonBridge). The project readme lists what is required.
What is this repository for?
It is a reference of focused C#/.NET examples. Each folder answers one practical question, such as “how do I add middleware to an Azure Functions isolated worker app?” or “how do I catch every exception from Task.WhenAll?”.
Which .NET version do I need?
It depends on the project: most target .NET 8, JsonSearchPatterns, PublicIP, and the Middleware/Dotnet6 samples target .NET 6, and SQLWrites targets .NET 10. FourKWinForm requires Windows.
Are these production-ready libraries?
No. They are learning-oriented demos. For production-grade packages, see Nilog (zero-allocation ILogger extensions) and Glass.Message (a modern WinForms MessageBox replacement).
Where can I find similar examples in Python?
See the companion Python projects collection — its LoadLibraries project shows the reverse direction of PythonBridge: calling a .NET library from Python.
- Most projects are learning-oriented and intentionally compact.
- This repo focuses on experiments, demos, and practical patterns rather than production-ready apps.
- Several projects can be opened directly in Visual Studio or run via
dotnet run.
This is a compact, colorful collection of .NET experiments covering cloud-native patterns, async techniques, AI integration, UI work, database writes, and system-level programming. It is a great sandbox for learning by building small, focused examples.
If you want to explore the repo in a more hands-on way, start with:
Mediatfor architecture patternsMiddlewarefor Azure Functions internalsSQLWritesfor database performance patternsSpectreDemofor terminal UX magicPythonBridgefor cross-language integration
- Python projects — standalone Python scripts and apps
- VB.NET Windows Forms examples — Visual Basic desktop experiments
- Developer knowledge base — includes a complete C#/.NET OOP guide and an Azure cheat sheet
Happy coding! 💻✨
Read all C# and .NET Code Examples guides online · Project overview · All developer projects