Monthly Archives: October 2016

Use bit operations in C#

C# defines several operators that perform bit operations. As you may be able to guess from the names, these operators manipulate the bits in an integer value. They operate on the value’s bits separately so they are sometimes called “bitwise … Continue reading

Posted in calculations, mathematics, variables | Tagged , , , , , , , , , , , , , | Leave a comment

Solve the equilateral triangles puzzle in C#

This post shows how to solve and display the solutions to the puzzle Puzzle: Find the equilateral triangles in C#. This example uses the following code to define the puzzle’s 25 solutions. // Define the solutions. Solutions = new List<int[]>(); … Continue reading

Posted in algorithms, games, graphics, mathematics | Tagged , , , , , , , , , , , , | 1 Comment

Set font size to fit a wrapped label in C#

The example Set font size to fit a label in C# shows how you can pick a font size to make text large but still fit inside a Label. This example is similar except it allows the text to wrap … Continue reading

Posted in drawing, fonts, graphics | Tagged , , , , , , , , , , , , , , | Leave a comment

Set font size to fit a label in C#

This program uses the following method to calculate the largest font size that the Label can use while still allowing the sample text to fit. // Return the largest font size that lets the text fit. private float GetFontSize(Label label, … Continue reading

Posted in drawing, fonts, graphics | Tagged , , , , , , , , , , , , | Leave a comment

Randomize two-dimensional arrays in C#

This example uses the following extension method to randomize two-dimensional arrays. // Randomize a 2D array. public static void Randomize<T>(this T[,] values) { // Get the dimensions. int num_rows = values.GetUpperBound(0) + 1; int num_cols = values.GetUpperBound(1) + 1; int … Continue reading

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

Get variable values by name in C#

The process for displaying variable values is somewhat convoluted, but it’s not too long. The example starts by using the following code to define some private and public fields. // Some form-level values. private string private_value1 = “This is private … Continue reading

Posted in arrays, reflection, variables | Tagged , , , , , , , , , , , , , , , | 1 Comment

Puzzle: Find the equilateral triangles in C#

This is a puzzle that was a while back on National Public Radio (NPR). How many equilateral triangles can you make with corners on the points drawn by the program? For this blog, the puzzle has two parts. First see … Continue reading

Posted in algorithms, games, graphics, mathematics | Tagged , , , , , , , , , , , , | 2 Comments

Randomly color an Apollonian gasket in C#

This example is similar to the example Draw an Apollonian gasket in C# except it fills the circles it draws with random colors. The program uses the following code to generate random colors. // Return a random color. private Random … Continue reading

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