Category Archives: calculations

Calculate the value of a monthly investment in C#

The magic of an investment with compound interest is that, over time, you get interest on the interest. For each month this program calculates the interest on the account balance. It then adds the interest and a monthly contribution to … Continue reading

Posted in algorithms, calculations, finance, mathematics | Tagged , , , , , , , , , , , | 2 Comments

Make generic Min and Max methods in C#

This example shows how you can make generic Min and Max methods to find the minimum and maximum values in a sequence of parameters. The Math namespace’s Min and Max methods are very useful, but they have two big drawbacks. … Continue reading

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

See how much time a checked block takes in C#

The post Control overflow behavior with checked and unchecked in C# explains how to use checked blocks to watch for integer overflow. If you don’t use checked, the program may encounter integer overflow errors without you knowing it. It seems … Continue reading

Posted in calculations, mathematics, performance, syntax | Tagged , , , , , , , , , , , , , , , | Leave a comment

Control overflow behavior with checked and unchecked in C#

C# handles overflow with different data types differently. You can control this to some extent with the checked and unchecked keywords. If you execute code inside a checked block and an int or long operation causes an overflow, the block … Continue reading

Posted in calculations, mathematics, syntax | Tagged , , , , , , , , , , , , , | 1 Comment