PV Function and Porting VB6 to C#

The use of Microsoft.VisualBasic from C# and VB.NET has been discussed thoroughly under this question. The Microsoft.VisualBasic namespace is fully supported, and will be around as long as .Net is around. There's no reason to avoid it.

EDIT: It's telling that at the time of typing, the other answers for this question are an incorrect reimplementation of the function, and a one-man-band unsupported library from Code Galleries. Come on guys, it would take a real major event for Microsoft to drop the financial functions from VB.

It's a different story for Microsoft.VisualBasic.Compatibility, which is exclusively for use by the VB6 upgrade wizard, EDIT has now been marked obsolete in .Net 4 (my prediction came true), and should not be used for new development. There would be some advantages in removing references to this, but personally I'd probably try to achieve a fully working port first referencing.Net 3.5.


Pretty straight forward to replicate in C#

    public static double PV(double Rate, int nPer, double Pmt, double FV, bool Type)
    {
        double ann = Math.Pow(1 + Rate, nPer);
        return -(FV + Pmt * (1 + (Type ? Rate : 0)) * ((ann - 1) / Rate)) / ann;
    }

Just a re-arrangement of the formula Microsoft provides.