Monthly Archives: August 2012

Create a class outside of any namespace statement in C#

When you create a class in C#, Visual Studio automatically puts it inside a namespace statement. If your project’s name is howto_remove_namespace, then by default that namespace is howto_remove_namespace. Did you know that you can create classes outside of any … Continue reading

Posted in classes, syntax | 2 Comments

Book Review: The Manga Guide to Linear Algebra

(Occasionally I post reviews of book that I think may interest programmers, in this case admittedly those with a mathematical inclination. I’ve been fairly remiss about not posting this one sooner.) The Manga Guide to Linear Algebra   $24.95, 264 … Continue reading

Posted in books, mathematics | Leave a comment

Generate random polygons in C#

I needed a method for generating random polygons for a graphics program and the following code shows the result. // Make a random polygon inside the bounding rectangle. private static Random rand = new Random(); public static PointF[] MakeRandomPolygon( int … Continue reading

Posted in algorithms, geometry, graphics | Leave a comment

Add extension methods to the Random class to generate double values within a specified range in C#

The Random class provides methods for generating pseudo-random numbers. The Next method has three overloaded versions that produce a non-negative integer, an integer between 0 and some upper bound, and between lower and upper bounds. Strangely the Random class’s NextDouble … Continue reading

Posted in extension methods | Leave a comment

Use a foreach loop to iterate over the items in an array or list in C#

You can use a foreach loop to iterate over the items in arrays, lists, collections, and other objects that have a GetEnumerator method. These loops are often more convenient than for or while loops because you don’t need to worry … Continue reading

Posted in arrays, lists, syntax | Leave a comment

Print the contents of a ListView control with data that doesn’t fit in one line in C#

The example Print the contents of a ListView control in C# explains how to print the data in a ListView control when its View property is set to Details. One difficulty when printing this kind of data is that a … Continue reading

Posted in controls, printing | Leave a comment

Make an application that safely manages Open, New, Save, and Save As commands in C#

This is a pretty involved example. The pieces are all simple but there are a lot of tightly integrated pieces. This example you create, edit, open, and save text and Rich Text format files. It provides New, Open, Save, Save … Continue reading

Posted in files, forms, user interface | 1 Comment

Add LINQ to the example that suggests words based on what the user is typing in C#

This example adds LINQ to the example Improve the example that suggests words based on what the user is typing in C#. It adds LINQ in two places: when it loads the list of words and when the program searches … Continue reading

Posted in algorithms | Leave a comment