VB“ Financial.Pmt”等价于C#? [英] VB "Financial.Pmt" equivalent in C#?
问题描述
Microsoft.VisualBasic程序集有一个内置函数。我可以像这样在VB中使用它:
There is a built in function from the Microsoft.VisualBasic assembly. I can use it in VB like this:
Financial.Pmt((dAPR / 100) / 12, iNumberOfPayments, dLoanAmount) * -1
我当前的项目在C#中,我需要使用此功能。网络上的答案说,只需添加名称空间和程序集,并在C#中使用相同的名称,但这是不对的! C#仍然无法识别该公式。
My current project is in C# and I need to use this function. Answers on the web say just add the namespace and assembly and use the same in C#- but this is not true! C# still does not recognize this formula.
那么我该如何在C#中使用use Financial.Pmt(甚至可以将源代码移植到该代码中)?谢谢您的帮助。
So how can I use use Financial.Pmt in C# (or perhaps even porting the source code to it)? Thanks for any help.
推荐答案
像这样:
using System;
using Microsoft.VisualBasic;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
double dAPR = 2;
Int32 iNumberOfPayments = 12;
double dLoanAmount = 10000;
Console.WriteLine(Financial.Pmt((dAPR / 100) / 12, iNumberOfPayments, dLoanAmount, 0, DueDate.EndOfPeriod) * -1);
Console.ReadLine();
}
}
}
- 类似于 Joel说,添加对Microsoft的引用。 VisualBasic程序集。
- 就像Rup在评论中说的那样,您必须为第4个和第5个参数提供默认值。
- Like Joel says, add a reference to the Microsoft.VisualBasic assembly.
- Like Rup says in a comment, you have to provide the defaults to the 4th and 5th arguments.
请在适当的时候使用C#中的Microsoft.VisualBasic 。它是.Net中受完全支持的核心库,并且包含一些有用的财务功能。
Do use Microsoft.VisualBasic from C# when appropriate. It's a fully supported core library in .Net and it contains some useful financial functions.
这篇关于VB“ Financial.Pmt”等价于C#?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!