Author Archives: Rod Stephens

Solution to puzzle: Zero rows and columns in an array in C#

This post gives four solutions to Puzzle: Zero rows and columns in an array in C#. If you want to try the puzzle for yourself, see that post before you read this one. This is a fairly long post, but … Continue reading

Posted in arrays, games | Tagged , , , , , , , , , | 3 Comments

Make a TextBox preview extender provider in C#

This example shows how to convert the TextBox preview techniques described in the last few posts into an extender provider. The previous examples showed the basic technique, but they were hard-wired to specific TextBox controls so they weren’t very flexible. … Continue reading

Posted in controls, extensions, user interface | Tagged , , , , , , , , , , , , , , | Leave a comment

Make the user enter a float in C#

The posts Preview TextBox changes in C# and Preview TextBox changes in C#, Part 2 show how you can make a TextBox accept only integers. This example is similar except it makes a TextBox only accept floats. This change is … Continue reading

Posted in controls, user interface | Tagged , , , , , , , , , , , , , , , | Leave a comment

Preview TextBox changes in C#, Part 2

Part 1 of this post explained how the example previews changes made by keyboard events. It then accepts or cancels the changes depending on whether the TextBox control’s new value is a valid integer (or the start of one as … Continue reading

Posted in controls, user interface | Tagged , , , , , , , , , , , , | Leave a comment

Preview TextBox changes in C#

One of the more annoying omissions from the Windows Forms controls is a way to preview changes to a TextBox before they occur. For example, suppose you want the user to enter a floating point value in a TextBox. The … Continue reading

Posted in controls, user interface | Tagged , , , , , , , , , , , , | 2 Comments

Use Array methods in C#

The example Sort and search arrays in C# shows how to use two useful Array methods: Sort and BinarySearch. This example demonstrates some other useful Array methods. For simplicity, this example uses arrays of characters to demonstrate the Array methods, … Continue reading

Posted in arrays, classes | Tagged , , , , , , , , , , , , , | Leave a comment

Puzzle: Zero rows and columns in an array in C#

This puzzle is given as a coding example in the book Cracking the Coding Interview by Gayle Laakmann McDowell. The puzzle is: Write an algorithm such that if an element in an M x N matrix is 0, its entire … Continue reading

Posted in arrays, games | Tagged , , , , , , , , | 1 Comment

Compare performance looping over DateTime and integer variables in C#

The example Find Friday the Thirteenths in C# doesn’t really worry about performance. It uses integers to loop over the dates within a range. For every year between the start and end dates, the code considers the 13th of each … Continue reading

Posted in performance, syntax | Tagged , , , , , , , , , , , , , , | Leave a comment

Find Friday the Thirteenths in C#

The following code shows how this example lists the Friday the Thirteenths between selected start and end dates. // List Friday the 13ths between the start and end dates. private void btnGo_Click(object sender, EventArgs e) { lstResults.Items.Clear(); // Get the … Continue reading

Posted in performance, syntax | Tagged , , , , , , , , , , , | 1 Comment

Use == and != to compare structs in C#

This example shows how you can overload the == and != operators to make it easier to compare structs. By default, for reference types (classes), == returns true if two references refer to the same object (reference equality). It returns … Continue reading

Posted in operators, syntax | Tagged , , , , , , , , , , , , , , , | Leave a comment