ASP.NET - how to use ref double[ ] in Microsoft.VisualBasic.Financial.IRR

Asked By anbu n on 28-Oct-11 07:49 AM

double[] _un_IRR = new double[Convert.ToInt32(lblCashfw_col.Text) - 1];

Double Guess = 0.0;


 Label lbl_Before_tax = (Label)this.PlaceHolder1.FindControl("TextBoxRow_Cashflow_23Col_" + j);

 Label lbl_Unlr_IRR = (Label)this.PlaceHolder1.FindControl("TextBoxRow_Cashflow_24Col_0");

 _un_IRR[j] = Convert.ToDouble(lbl_Before_tax.Text);

 lbl_Unlr_IRR.Text = (Microsoft.VisualBasic.Financial.IRR(ref _un_IRR, Guess)).ToString();

...............................

in above code , when the code comes over  last line the following error is displayed ......

if dont use the ref keyword the following error is shown,

Argument '1' must be passed with the 'ref' keyword   

if i add ref keyword, i am getting following error

Arguments are not valid.

..

so how to use ref double[ ] in Microsoft.VisualBasic.Financial.IRR

Jitendra Faye replied to anbu n on 28-Oct-11 07:57 AM
Use can use like this-

public static double IRR(
	ref double[] ValueArray,
	double Guess
)


Follow this example-

' Define money format.
Dim MoneyFmt As String = "###,##0.00"
' Define percentage format.
Dim PercentFmt As String = "#0.00"

Dim values(4) As Double
' Business start-up costs.
values(0) = -70000
' Positive cash flows reflecting income for four successive years.
values(1) = 22000
values(2) = 25000
values(3) = 28000
values(4) = 31000

' Use the IRR function to calculate the rate of return.
' Guess starts at 10 percent.
Dim Guess As Double = 0.1
' Calculate internal rate.
Dim CalcRetRate As Double = IRR(values, Guess) * 100
' Display internal return rate.
MsgBox("The internal rate of return for these cash flows is " & 
    Format(CalcRetRate, CStr(PercentFmt)) & " percent.")

Hope this will help you.