C# Code Snippets

Jump to: navigation, search

C# Code snippets / C# Examples / C# Samples

Visual C# Developer Center is relaxing...
A C# code snippet is a brief example of useful C# source code or Visual C# source code. They answer the questions which begin "How do I…". Sometimes called a recipe, a code snippet usually performs a single function. Being mere fragments of C# source code, the snippets often omit the required using statements. C# source code snippets are categorized alphabetically by namespace. Similar to a code gallery, we have places our fully functional C# methods in our C# source code bankC# source code respository or C# cookbook—for all to share.

Consult the alphabetical list of the C# code snippet namespaces.

Microsoft Visual Studio Express Editions
Download a free, .NET integrated development environment (IDE) for software development.
VSELogo2.jpg


C# Code Library

 
 


Microsoft.Win32


System

  • Compare dates - see how to compare dates (DateTime) and work with time intervals (TimeSpan).
  • Get enum values - get and display the names or values of the enum declaration.
  • Make a utilities class - create a separate class to hold your utility classes for reference by other classes.
  • Use enumerations - illustrates the declaration and use of enumerated types (enum keyword).


System.Collections

  • Enumerate an array - enumerate over the elements of a multidimensional array using the IEnumerator interface.


System.Collections.Generic


System.Data.SqlClient


System.Diagnostics.Contracts

  • Parameter validation assertion - returns true if the specified digit is found in the given number. But, gives an "Assertion Failed" message if the digit is improper.


System.DirectoryServices


System.Dynamic


System.Exception


System.Globalization


System.IO


System.Management


System.Media


System.Net

  • HTTP Post - send an HTTP Post and get the response.
  • System.Net.Mail - SMTP e-Mail functions.


System.Numerics


System.Reflection


System.Runtime.InteropServices


System.Runtime.Remoting


System.Runtime.Serialization


System.Security.Principal


System.ServiceProcess


System.String


System.Text

  • Encode a string - see examples of ASCII, UTF-8, UTF-16, and UTF-32 character set conversions.


System.Text.RegularExpressions


System.Threading


System.Windows.Forms


System.Xml


See also

C# Online.NET