Monthly Archives: October 2012

Use a for loop to recursively iterate over the items in an array with an unknown number of dimensions in C#

When it starts, the program executes the following code. private void Form1_Load(object sender, EventArgs e) { string[, ,] values = { { { “(0, 0, 0)”, “(0, 0, 1)”, “(0, 0, 2)”, “(0, 0, 3)”, }, { “(0, 1, 0)”, … Continue reading

Posted in algorithms, arrays, syntax | 2 Comments

Make an extender provider that makes it easy to preview TextBox changes in C#

The last few posts explained how to preview changes to a TextBox and ensure that the user could only enter an integer or a floating point value. Those examples demonstrated a basic technique but were hard-wired to specific TextBoxes so … Continue reading

Posted in controls, user interface | Leave a comment

Make a TextBox that lets the user only enter floats in C#

The posts Make a TextBox let the user enter only integers in C# and Make a TextBox let the user enter only integers in C#, Part 2 show how you can make a TextBox accept only integers. This example is … Continue reading

Posted in controls | Leave a comment

Make a TextBox that lets you preview and cancel changes to its text 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’s new value is a valid integer (or the start of one as in … Continue reading

Posted in controls | Leave a comment

Make a TextBox that lets you preview and cancel changes to its text in C#

One of the most annoying omissions in the Windows Forms controls is a way to validate 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 | Leave a comment

Solution: 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 | 3 Comments

Use methods provided by the Array class in C#

The example Use the Array class’s Sort and BinarySearch methods in C# shows how to use two useful methods provided by the Array class. This example demonstrates some other useful methods provided by the Array class. For simplicity, this example … Continue reading

Posted in arrays, classes | 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. (I’ll post a review later after I’ve finished going through it.) The puzzle is: Write an algorithm such that if an … Continue reading

Posted in arrays, games | Leave a comment

Compare the times needed to loop over dates by using DateTime variables and integers in C#

The example Find all of the Friday the Thirteenths between two dates in C# 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 | Leave a comment

Find all of the Friday the Thirteenths between two dates 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 | Leave a comment