Tag Archives: variables

Determine whether a year is a leap year in C#

Detecting leap years is basically trivial because the DateTime data type provides an IsLeapYear method to do just this. The example uses the following code to display the leap years between the two entered dates. // List leap years between … Continue reading

Posted in miscellany, variables | Tagged , , , , , , , , , , | Leave a comment

Compare the performance of the int, long, and byte data types in C#

The example Compare the performance of the float, double, and decimal data types in C# compares the performance of the float, double, and decimal data types. This example performs a similar test for the int, long, and byte data types. … Continue reading

Posted in performance, variables | Tagged , , , , , , , , , , , | Leave a comment

Compare the performance of the float, double, and decimal data types in C#

A computer’s math coprocessor typically gives the best performance with a particular data type. To see which works best on my system and to learn how big the difference is, I wrote this program to compare the performance of calculations … Continue reading

Posted in performance, variables | Tagged , , , , , , , , , , | 6 Comments

Loop over an array of unknown dimension in C#

The previous post Loop over entries in an array of unknown length in C# explains how to loop over the entries in a one- or two-dimensional array, but what do you do if you don’t know how many dimensions an … Continue reading

Posted in algorithms, arrays, recursion, variables | Tagged , , , , , , , , , , , , , , , , | 1 Comment

Loop over entries in an array of unknown length in C#

One way to loop through the items in an array is to hard code its length into the program. Alternatively you can use the array’s Length property to determine how many items it contains at runtime. Then if you later … Continue reading

Posted in arrays, variables | Tagged , , , , , , , , , , , , | Leave a comment

Take actions depending on the day of the week in C#

When the program starts, it uses the following code to display a different message in two different ways for each day of the week. // Display a message that depends on the day of the week. private void Form1_Load(object sender, … Continue reading

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

Find the Friday following a given date in C#

This example shows how you can find the Friday following a particular date. You can use a similar method to find other days of the week following a specific date. (Note that I have updated this example from its original … Continue reading

Posted in variables | Tagged , , , , , , , , , , , | 2 Comments

Define and use bit masks in C#

The example Understand bit masks in C# explains how to use bit masks. To define a bit mask, simply create an enum and give it the Flags attribute as in the following code. [Flags] private enum BitmaskEnum { Value1 = … Continue reading

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

Understand bit masks in C#

Some values, including some properties defined by the .NET Framework, are bit masks. That means each bit in a value means something. For example, the AnchorStyles enumeration that determines how controls are anchored in their parents defines four values: Top, … Continue reading

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

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