Code written in C#

Bitfield enums and the Flags attribute

# If you want to use bitfield enums, use the Flags attribute and powers of 
# 2. You can use bitwise operations such as OR to combine values.

[Flags]
enum Abcd {A = 1, B = 2, C = 4, D = 8}
Language C# / Tagged with enums

Comment your regex scripts

.NET Regular Expressions allow you to embed comments and whitespace within pattern strings making them clearer to read (because of the whitespace), and easier to maintain (due to the modularity).

To use this feature you must turn on the RegexOptions.IgnorePatternWhitespace flag.  This can be achieved either by using the RegexOptions enumerated datatype or, via the (?x) mode modifier.  Therefore the following two examples are functionally identical:

Regex re = new Regex( 
        @"           # This pattern matches Foo
            (?i)     # turn on insensitivity
                     # The Foo bit
            \b(Foo)\b "
        , RegexOptions.IgnorePatternWhitespace ) ;


    Regex re = new Regex( 
        @"(?x)
                    # This pattern matches Foo
            (?i)    # turn on insensitivity
                    # The Foo bit
            \b(Foo)\b "
        ) ;
Language C# / Tagged with regex

Different ways to create a thread-safe gui

With .NET 2.0 and with the new "anonymous delegates" feature in C#, doing multi threaded responsive GUIs is now easier. In fact, you get multiple choices on how to accomplish this task. But which choice is the best? and what does "best" really mean? more elegant? faster? more readable? all of the above?

private void displayError2(string message)
{
    Func del = delegate
    {
        errorDisplay.Show(message);
    };
            
    Invoke(del);
}
Language C# / Tagged with delegates