Monthly Archives: September 2014

Use nullable parameters in C#

This example shows how you can use nullable parameters to simulate optional parameters. The example Use null to simulate optional parameters in C# explains how you can pass null to a method to simulate optional parameters, but that only works … Continue reading

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

Use null to simulate optional parameters in C#

This example shows how you can use null to simulate optional parameters in older versions of C#. The example Use overloaded methods to simulate optional parameters in C# shows how you can use overloaded methods to simulate optional parameters. Another … Continue reading

Posted in OOP, syntax | Tagged , , , , , , , , , , | 1 Comment

Use overloaded methods to simulate optional parameters in C#

This example shows how you can simulate optional parameters if you’re using an older version of C#. Named and optional parameters were introduced in C# 2010. If you’re using an older version, you should probably upgrade if you can. But … Continue reading

Posted in OOP, syntax | Tagged , , , , , , , , , | 1 Comment

Calculate and highlight DataGridView values in C#

This example shows how to calculate and highlight DataGridView values at run time. It uses the following code to initialize its DataGridView control. It sets each item’s description, unit price, and quantity, but not its total cost. // Make some … Continue reading

Posted in controls, user interface | Tagged , , , , , , , , , | 3 Comments

Initialize DataGridView controls with objects in C#

This example shows how to easily initialize DataGridView controls to display the properties of items. This example uses the following OrderItem class. Notice that the constructor calculates the TotalCost from the Quantity and UnitPrice. public class OrderItem { public string … Continue reading

Posted in controls, user interface | Tagged , , , , , , , | Leave a comment

Draw a colored fractal curve generated by prime numbers in C#

This example shows how to draw a colored fractal curve generated by prime numbers. See the example Draw a fractal curve generated by prime numbers in C# for the basic algorithm. This example assigns colors to line segments based on … Continue reading

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

Draw a fractal curve generated by prime numbers in C#

This example shows how to draw a fractal curve generated by prime numbers. It’s a modification of the earlier example Draw a fractal generated by prime numbers in C#. The basic idea is follow these rules: Start at the point … Continue reading

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

Set DataGridView column styles in C#

You can set DataGridView column styles by setting a column’s DefaultCellStyle property. It determines the column’s appearance including its foreground color, background color, font, alignment, and colors to use when an item is selected. To set a column’s style at … Continue reading

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

Use the predefined system colors in C#

The static System.Drawing.SystemColors class defines properties that give the system colors. These include colors for such items as active objects, highlighted text, captions, and window frames. This example uses the following code to list the defined system colors. // List … Continue reading

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

Encrypt or decrypt files in C#

The following EncryptFile and DecryptFile methods encrypt or decrypt files at a very high level. // Encrypt or decrypt a file, saving the results in another file. public static void EncryptFile(string password, string in_file, string out_file) { CryptFile(password, in_file, out_file, … Continue reading

Posted in cryptography, files | Tagged , , , , , , , , , , , | 5 Comments