Judge Character with Char.Is

No Comments »

There are multiple static “Is” methods on the Char structure that help determine a character’s category. All of these methods (except IsSurrogatePair) take a single character argument (or string and index) and return a boolean whether the character is in the corresponding category.

Read the rest of this entry »

Convert Binary to Base64 String

No Comments »

Modern applications increasingly use plain text to store and share data, especially in XML and SOAP formats. However, binary data cannot be represented directly in plain text, so one popular method is to convert binary to Base64 format.

Read the rest of this entry »

String.IsNullOrEmpty Shootout

2 Comments »

Given a string ’s’, which of the following expressions is faster?

1. String.IsNullOrEmpty( s )

2. s == null || s.Length == 0

Read the rest of this entry »

Having Pun with C#

3 Comments »

Here is a collection of puns that only a C# programmer could appreciate:

Nerds

Read the rest of this entry »

KeyedCollection: Dictionary for Values with Embedded Keys

1 Comment »

If you need a collection of objects accessed by a key, and the key is one of the object’s properties, then you should use the KeyedCollection class instead of Dictionary. For example, you would use a KeyedCollection to store Employee objects accessed by the employee’s ID property.

Read the rest of this entry »