Monthly Archives: August 2015

Compare the speeds of the conditional operator (ternary operator ?:) and the if-else statement in C#

The conditional operator (also called the ternary operator) looks confusing enough that some programmers assume it must be more efficient than a comparable but longer if-else statement. This example uses the following code to compare the speeds of the conditional … Continue reading

Posted in performance, syntax | Tagged , , , , , , , , , , | 5 Comments

Use the conditional operator (ternary operator ?:) in C#

The conditional operator (also called the ternary operator) evaluates a boolean expression and returns one of two values depending on the result. If the expression is true, the operator returns the first value. If the expression is false, the operator … Continue reading

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

Declare and initialize empty arrays in C#

This is a handy trick for working with possibly empty arrays. A C# program cannot use an array’s properties and methods until the array is instantiated. For example, the following code declares an array and then tries to use its … Continue reading

Posted in arrays, syntax, tips | Tagged , , , , , , , , , , , , , , | Leave a comment

Make a bobblehead in C#

The example Draw a big-headed politician in C# shows how to draw a person with a really big head. To make the program work, you need to separate the person’s head and body. The program then positions the head. If … Continue reading

Posted in algorithms, animation, graphics, image processing | Tagged , , , , , , , , , , , , , , , | 2 Comments

Draw a big-headed politician in C#

This example shows how you can draw a big-headed person such as a politician. Before I start, let me say I’m not trying to bash Donald Trump in particular here. Originally I was planning to make images for all of … Continue reading

Posted in algorithms, graphics, image processing | Tagged , , , , , , , , , , , , , , | 1 Comment

Use a queue to draw a breadth-first colored binary tree in C#

The example Draw a breadth-first colored binary tree in C# shows how to use a Stack to draw a binary tree in depth-first order. The program builds a Stack representing the bottom (trunk) level of the tree. For each level, … Continue reading

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

Draw a breadth-first colored binary tree in C#

The example Draw a colored binary tree in C# shows how to use recursion to draw a colored binary tree. If you look closely at a tree of high degree, however, you’ll notice a problem. The program draws a branch … Continue reading

Posted in algorithms, drawing, fractals, graphics | Tagged , , , , , , , , , , , , , , | 4 Comments

Draw a colored binary tree in C#

This example shows how you can modify the example Recursively draw a binary tree in C# to draw a colored binary tree. It draws branches at different depths in different colors and with different thicknesses. The main recursive method in … Continue reading

Posted in algorithms, drawing, fractals, graphics | Tagged , , , , , , , , , , , , , , , , | 1 Comment

Recursively draw a binary tree in C#

This example shows how you can use recursion to draw a binary tree. Recursion occurs when a method calls itself. It may call itself directly (simple recursion) or indirectly by calling another method that calls the first (indirect recursion). It … Continue reading

Posted in algorithms, drawing, fractals, graphics | Tagged , , , , , , , , , , , , , , | 10 Comments

Save images in an Access database in WPF and C#

The example Display images in an Access database in WPF and C# shows how you can display images saved in an Access database. Of course that begs the question, “How do you save images in the database in the first … Continue reading

Posted in database, graphics, image processing, Office | Tagged , , , , , , , , , , , , , , , | Leave a comment