Skip to content
David Cumps
BitArray Class

BitArray Class

Contains an array of true/false values. Resizable through the Length property. Supports bitwise operations.

Comparer Class

Comparer Class

Default comparer used when sorting, for example with an ArrayList. Implements the IComparer interface.

Delegate Class

Delegate Class

Holds a reference to a method; declared in a single line, with the framework providing the underlying implementation.

EventArgs Class

EventArgs Class

EventArgs carries event data; use it for events without data and derive from it to pass custom data.

EventHandler Delegates

EventHandler Delegates

EventHandler and EventHandler<T> let you define events without declaring your own delegate, plus a pattern for disposing event listeners.

Exception classes

Exception classes

Exception class hierarchy, catch ordering, finally, try/catch/finally scopes and the recommended constructors for custom exceptions.

Generic Types

Generic Types

Generics let the caller fill in type placeholders, giving strongly typed collections with compile-time type checking and optional constraints.

GZipStream Class

GZipStream Class

Compresses and decompresses data in gzip format. Output is slightly larger than DeflateStream because of extra header information.

Hashtable Class

Hashtable Class

Non-generic key-value collection of DictionaryEntry objects, accessed by key rather than by index and stored by hash code.

IComparable Interface

IComparable Interface

IComparable is required for sorting. CompareTo returns less than 0, 0 or greater than 0 to order the current object relative to another.

IConvertible Interface

IConvertible Interface

Enables a class to be converted to a base type such as Boolean, Byte, Double or String, plus widening, narrowing and operator conversions.

IDisposable Interface

IDisposable Interface

Enables users of your class to free the resources an instance has consumed. Implement it for disposable members or native resources.

MemoryStream Class

MemoryStream Class

Provides an in-memory Stream for temporary data, for example to avoid keeping a file locked by a FileStream for long.

Reference Types

Reference Types

Reference type data lives on the heap and is cleaned up by the garbage collector; copying a reference copies only the pointer.

Regex Class

Regex Class

Used to work with regular expressions: anchoring patterns safely, plus examples of matching, replacing and named groups.

Snippets

Snippets

C# snippets: operator overloading on an immutable struct, and a Predicate used with Array.TrueForAll.

SortedList Class

SortedList Class

Key-value pair based collection. Contains DictionaryEntry objects. Accessible by index and key. Sorts items when they are added.

Stream Class

Stream Class

A stream is an abstraction of a sequence of bytes, which helps isolate the programmer from the underlying implementation.

StringBuilder Class

StringBuilder Class

A StringBuilder keeps an internal buffer instead of allocating a new string every time. The default capacity is 16 characters.

Value Types

Value Types

Value types: built-in types, structures, enums and nullable types, how they hold and copy values, and good practices for using them.

Using DebugView and C#

Using DebugView and C#

Writing debug messages from C# with System.Diagnostics and reading them, locally or remotely, with Sysinternals DebugView.

Passing Bitwise OR Enum Values

Passing Bitwise OR Enum Values

How to pass several options in one enum parameter, like RegexOptions, using powers of two, bitwise OR and bitwise AND.

Parameterized Queries with MySQL

Parameterized Queries with MySQL

Switching to parameterized queries with MySQL and MyODBC: don't put quotes around the ? placeholders, or you insert a question mark.

Custom WordWrapper

Custom WordWrapper

A C# word wrap method with a maximum width and an optional prefix, written for a forum question when I couldn't find one online.

Outlook and C#: Gather Addresses

Outlook and C#: Gather Addresses

A C# console app that walks an Outlook folder and collects every e-mail address from senders, recipients and message bodies.

Small Console ChatServer

Small Console ChatServer

A small C# console chat server: a TcpListener on its own thread, one Connection object per client, and every message broadcast to all.

C# Script

C# Script

CS-Script: a small tool that compiles and runs a single .cs file in memory, like a batch script for C#.

Including Resources in .exe

Including Resources in .exe

Embedding the Non-Rectangular Form's bitmap in the .exe as a resource, and loading it with one line of C#.

Non-Rectangular Form

Non-Rectangular Form

Turning any bitmap into a non-rectangular Windows Form in C#: build a Region from every non-transparent pixel.

A Console IRC Bot

A Console IRC Bot

Getting on IRC with C#: a console bot that connects, logs in, joins a channel and reacts to server and user commands.

Basic C# Examples

Basic C# Examples

Most posts here assume a lot of background, so I asked fellow students for their C# questions and answered them with basic examples.