I was doing some rudimentary math solutions in C# the other day and was looking at the System.Math namespace in the hope of finding a MOD (modulo) method but came up blank. I started down the C programming path of using **%** but then realized that **System.Math.DivRem** *was* the new name for what I needed.

int remainder,result;

result = Math.DivRem(10, 3, out remainder);

Console.WriteLine(result.ToString()); //gives 3

Console.WriteLine(remainder.ToString()); //gives the remainder of 1

I need to make a concerted effort to have a more in depth look at the various .NET name spaces and the shortcuts they provide to common problems. Most of my opinions on programming are heavily informed by the functional programming construct of C and to a lesser extent VB … may be that is not such a bad thing?

Technorati Tags: MOD function in C#