Count Items in a C# Enum

4 Comments »

You can count the number of constants defined in a C# enumeration with the static Enum.GetNames method. This returns an Array containing the names of the constants defined in the enumeration. You can then check the Array’s Length property.

Read the rest of this entry »

In C#, a string is a String

1 Comment »

C# includes a number of pre-defined “built-in” data types. Each built-in data type is represented by a class in the System namespace that inherits from the base System.Object class. For example, an integer is represented by the System.Int32 class, and a string is represented by the System.String class.

C# defines an alias keyword for each built-in type. The alias keyword and its corresponding C# type are interchangeable. For example, you can define a string with the “string” keyword or “System.String” type:

Read the rest of this entry »

C# String Tips

90 Comments »

The .NET string class is quite comprehensive, yet some common string functions are missing or not entirely obvious. This article provides quick tips on using .NET strings.

Read the rest of this entry »

Truncate File Path with Ellipsis

17 Comments »

The Microsoft .NET Framework is quite comprehensive, but occasionally an obvious function slips through the cracks and you have to use InteropServices to access the Windows API.

One such obvious miss is the ability to truncate a file path. If you are drawing text and know the font and desired output size, you can use the WinForms TextRenderer class. But to truncate a file path to a specific number of characters, you need the “Shell Lightweight Utility Library” function PathCompactPathEx:

Read the rest of this entry »

Determine the .NET Versions on which an Application is Compiled and Running

No Comments »

The version of .NET against which you compile an application or assembly may not be the same version of .NET on which the application is currently running. A .NET application should always be able to run on the same or newer version of .NET against which it was compiled.

This is because .NET is backward compatible. This means that an application compiled on .NET v1.1 should run OK on .NET v2.0 and v3.0. But an application compiled on .NET v2.0 will not run on .NET v1.1.

Read the rest of this entry »

Change Font Style

13 Comments »

Changing a font style is a bit easier than changing its size, as there is a Font constructor that accepts a font and style as arguments. For example, to bold a label’s font:

Read the rest of this entry »

Change Font Size

16 Comments »

An inspection of the Font class will reveal that every public property is read-only. This means to change a font’s size, you need to create a new Font object with all the same properties of your current font but with the new size. Here is a handy method to do just that:

Read the rest of this entry »

Hide Form from Alt+Tab

33 Comments »

When you show a .NET Form, by default the form will appear in the Windows Start bar and in the list of open windows shown when the user presses Alt+Tab.

Read the rest of this entry »

.NET Assembly FAQ – Part 4 – Global Assembly Cache

29 Comments »

This multi-part article answers common questions about assemblies, the basic building blocks of .NET applications. This Part 4 covers shared assemblies and the Global Assembly Cache.

Read the rest of this entry »

List Drives and Volumes from .NET

2 Comments »

The .NET Framework v2.0 did a nice job filling many holes in the System.IO namespace, especially when it comes to managing the file system. One such addition is the DriveInfo class, which enables you to determine what drives are available, their type, capacity and available free space.

Read the rest of this entry »

« go backkeep looking »