Tag Archives: example

Find Mersenne primes in C#

Mersenne primes are prime numbers of the from 2n – 1 for some integer n. For example, 22 – 1 = 4 – 1 = 3 and 3 is prime, so 3 is a Mersenne prime. This example uses a … Continue reading

Posted in algorithms, mathematics | Tagged , , , , , , , , , | Leave a comment

Display a progress bar with text in WPF and C#

As is so often the case in WPF, the solution is simple after you spend a few hours figuring out what controls to use. This example uses a normal Grid control that holds a StackPanel. The following code shows the … Continue reading

Posted in controls, user interface, wpf, XAML | Tagged , , , , , , , , , , , , , | 1 Comment

Convert between ragged arrays and two-dimensional arrays

Ragged arrays are arrays that hold other arrays, as opposed to two-dimensional arrays. They are called “ragged arrays” because they work like two-dimensional arrays (or higher-dimensional arrays) where each row in the array can hold a different number of elements. … Continue reading

Posted in algorithms, arrays, extension methods, generic | Tagged , , , , , , , , , , , | Leave a comment

Perform image hashing in C#

Image hashing or (perceptual image hashing) attempts to reduce an image to a concise code that represents the image so you can compare it to other images to see if they are the same. This example uses a difference hash … Continue reading

Posted in algorithms, graphics, image processing | Tagged , , , , , , , | Leave a comment

Use the automatic code converters at developerFusion to convert C# code into Visual Basic, Ruby, and Python

The developerFusion web site provides code converters that let you translate between C#, Visual Basic, Ruby, and Python. One of the most important uses for reflection is analyzing code to figure out what it does. Once you know what the … Continue reading

Posted in programs, reflection, syntax | Tagged , , , , , , , , , , , , , , , | 1 Comment

Copy ListView data into an array in C#

This example uses the following ListView extension method to copy ListView data into a two-dimensional array of strings. // Return the ListBox’s contents in a string[,]. public static string[,] GetListViewData(this ListView lvw) { // Get the number of rows and … Continue reading

Posted in arrays, controls, strings | Tagged , , , , , , , , , , | Leave a comment

Draw the spiral of Theodorus in C#

The spiral of Theodorus (which is also called the square root spiral, Einstein spiral, and Pythagorean spiral) was first devised by the Greek mathematician Theodorus of Cyrene during the 5th century BC. The spiral consists of a sequence of right … Continue reading

Posted in algorithms, drawing, graphics, mathematics | Tagged , , , , , , , , , , , , , | Leave a comment

Add LINQ to autocomplete in C#

This example adds LINQ to the example Improve autocomplete suggestion in C#. It adds LINQ in two places: when it loads the list of words and when the program searches for the best matches that begin with a particular letter. … Continue reading

Posted in algorithms, LINQ, strings | Tagged , , , , , , , , , , , , , , | Leave a comment

Improve autocomplete suggestion in C#

This example improves on the example Suggest autocomplete words in C#. The previous example loads all of its words into a big array. Then, to find the words that start with a particular letter, the program uses a binary search … Continue reading

Posted in algorithms, strings | Tagged , , , , , , , , , , , , , , | 1 Comment

Suggest autocomplete words in C#

This example shows one way that a program can suggest words for the user. When I type something on my phone, it displays a list of possible words for autocomplete below the editing area. For example, if I type “gping” … Continue reading

Posted in algorithms, strings | Tagged , , , , , , , , , , , , , , | 5 Comments