Monthly Archives: January 2014

Use the FileSystemWatcher component to build a spooling program in C#

SPOOL is an ancient computer acronym dating from the 1950s that stands for “Simultaneous Peripheral Operations On-Line.” It is a technique in which jobs are placed in a queue in memory or on disk for later processing. The most common … Continue reading

Posted in controls, files | Leave a comment

Use Visual Studio to implement an interface explicitly or implicitly in C#

Suppose you create a class and in the declaration you indicate that it implements an interface. If you right-click the interface’s name, the dropdown displayed by Visual Studio includes an “Implement Interface” submenu. If you look at the picture on … Continue reading

Posted in interfaces, syntax | Leave a comment

Understand ways to end case blocks in C#

Consider the following code that executes a switch statement. string result = “”; int control = 1; switch (control) { case 1: case 2: result = “One or two”; break; case 3: result = “Three”; for (; ; ) ; … Continue reading

Posted in syntax | 2 Comments

Control loops that use floating-point values in C#

Sometimes you might need to use a floating-point variable that loops over a range of values. For example, you might want a value to step through the values 0.0 through 1.0 in increments of 0.1. The sequence of numbers would … Continue reading

Posted in calculations, mathematics, variables | Leave a comment

Display sample dates and currency values for the locales defined on the system in C#

This program uses the following simple CultureData class to store information about a locale. // A class to store cultre data. public class CultureData { // The CultureInfo. public CultureInfo Info; // Initializing constructor. public CultureData(CultureInfo info) { Info = … Continue reading

Posted in internationalization, localization | Leave a comment

Make locale-aware methods use a new culture at runtime in C#

The example Change a localized program’s locale at runtime to test it in multiple languages and locales in C# explains how to change a program’s locale and reload its controls for the new locale. However, that doesn’t change the thread’s … Continue reading

Posted in internationalization, localization | Leave a comment

Use PLINQ and a lambda expression to select prime numbers from an array in C#

The example Use PLINQ to select even numbers from an array in C# uses PLINQ (Parallel LINQ) to find the even numbers in an array of random values. This example uses a similar technique to do something slightly more interesting: … Continue reading

Posted in LINQ, performance | Leave a comment

Use PLINQ to select even numbers from an array in C#

This example is really a demonstration of PLINQ, since you probably won’t need to use this technique to find even numbers. (If you do need to generate even numbers, it’ll be a lot faster and easier to simply pick random … Continue reading

Posted in LINQ, performance | 2 Comments

Use the BitConverter class to write extension methods to convert between byte arrays and strings of hexadecimal values in C#

This is a new version of the example Write extension methods to convert between byte arrays and strings of hexadecimal values in C# that takes a slightly different approach. The following code shows the new versions of the extension methods. … Continue reading

Posted in extension methods, extensions, strings | Leave a comment

Disable the charms gesture in Windows 8 (and learn a bit about user interface design)

I still really like my new laptop (see my post Quick review of a new laptop), but one thing I really hate about Windows 8 is the way the charms bar kept popping up at seemingly random times. I would … Continue reading

Posted in Uncategorized | 2 Comments