ARTICLE

Leveraging VB.NET Base Classes

Posted by Caonabo Ruiz Articles | Visual Basic 2010 April 22, 2003
This article shows you how to leverage the power of VB.Net Financial base class library using C#. The .Net unify class architecture model allows .Net languages to leverage class libraries implemented in other class libraries.
Download Files:
 
Reader Level:

Introduction

Multiple language implementation has an inherited powerful advantages. The .Net unify class architecture model allows .Net languages to leverage class libraries implemented in other class libraries. This article shows you how to leverage the power of VB.Net Financial base class library using C#.

Article

Since no language implementation can provides classes for every possible thing, C# is not the exception, when it comes to financial functions, C# nor the Math class provides you any implementation of  financial classes or functions.  If for example you need to develop a mortgage loan calculation program using C#, your basic choices are: 1) Roll your own one,  2) Use another language which implements the desired functionality, 3) Use a commercially available COM objects, or  4) Leverage the base class library of another .Net language.

In this article I'll show you a WinForm mortgage loan calculator using a home grown Pmt formula (choice #1), and I'll leverage the financial base class implemented in VB.Net (choice #4).

Running the sample code should display a form with a principal amount = 10000, an interest rate = 8, and a duration in months = 36.  By pressing the PMT button, the calculated PMT by the C# code and financial base class will show at the bottom of the window.

The actual code that executes:

double P = textBox1.Text.ToDouble();
double I = textBox2.Text.ToDouble()/1200;
double M = textBox3.Text.ToDouble();
Cpayment.Text = ((
double)(P * (I/(1 - Math.Pow((1 + I), -M))))).ToString();
VBpayment.Text = Math.Abs(Financial.PMT(I,M,P,0,0)).ToString();

Now, to have access to the Financial.PMT method, in the Solution Explorer you need to add Microsoft.VisualBasic as a reference to your project (see below), and then you may use the using declarative statement as follows:

using Microsoft.VisualBasic;

 

Performance vs. Convenience

Although the C# implementation of PMT is a bit better performer than the PMT VB Financial PMT function by a 3 to 8 microseconds in large iteration (10,000 thru 500,000), the cost of development plus maintenance of the C# implementation of all financial functions will outweigh the diminished gain in cycles.

Conclusion:

Having access to .Net languages base classes from any language is a powerful concept.  Experiment with other .Net languages and discover how easy you can leverage the concept of multi-language implementation that .Net has brought to us.

share this article :
post comment
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Nevron Diagram
Become a Sponsor