About C# Examples

C# Examples is a collection of short, practical code examples for C# and .NET developers. Each article answers one concrete question, such as how to read an Excel file, hash a string or update the UI from a background thread, with code you can paste into a project and an explanation of the parts that usually go wrong.

The site has been online since 2014 and is written and maintained by Turgay.

What you will find here

  • More than 100 examples covering the C# language, collections and LINQ, strings and dates, files and XML, databases, WinForms and Windows APIs, sorting and search algorithms, and Bootstrap for ASP.NET developers.
  • A learning path for people new to C#.
  • A page of interview questions and answers for job seekers.
  • An index of every article on the All Posts page.

How the examples are written

Every article was reviewed and rewritten in 2026 for current .NET and modern C#. When an older API is obsolete or unsafe, such as BinaryFormatter, WebClient or password-based SMTP for Outlook.com, the article shows the current replacement first and explains the old approach only for people maintaining legacy code. Windows-only code is marked as such, together with the project settings it needs.

The examples favour clarity over cleverness. They are meant to be understood and adapted, not copied blindly into production, and each one points out the edge cases worth testing in your own code.

Found a mistake?

Code examples age quickly and mistakes happen. If something does not compile, gives a different result than the article says, or could be done better, please let me know through the contact page. Corrections are welcome and are usually published within a few days.

Advertising

The site is free to read and is supported by advertising from Google AdSense. Ads never influence what is written. See the privacy policy for how advertising cookies work and how to opt out.