我有這個C++代碼,並將其轉換爲c#(.net框架4)代碼。 有沒有人爲我的malloc,免費和sprintf方法提示?C++代碼(malloc方法)以c#代碼
int monate = ee;
double *forward;
double *backward;
size_t bytes = 6*sizeof(double);
forward = (double *)malloc(monate * bytes);
backward = (double *)malloc(monate * bytes);
for (int i = 0; i <= monate; i++) {
forward[i] = 0.;
backward[i] = rate;
}
forward[0] = auszahlungsbetrag;
backward[0] = 0.;
backward[monate] = rate + rest;
double ez = esolver(12 , monate, forward, backward);
printf("Effektivzins: %.2f\n", ez);
char tmp0[256];
sprintf (tmp0, "Rate: %.2f (%f)" , rate, rate);
writeToLogFile(tmp0);
char tmp[256];
sprintf (tmp, "Effektivzins: %.2f (%f)" , ez, ez);
writeToLogFile(tmp);
free(forward);
free(backward);
這是我轉換後的c#代碼。對於malloc方法,free和sprintf我有一些麻煩將它轉換爲c#。
using System;
namespace Zinsrechner
{
public static class Basic
{
public static void basic(double aa, double auszahlungsbetrag, double cc, int ee, double rest)
{
Writelog.writeToLogFile("Start der Berechnung, Type BASIC");
Writelog.writeToLogFileDouble("Kreditvolumen: ", aa);
Writelog.writeToLogFileDouble("Auszahlungsbetrag: ", auszahlungsbetrag);
Writelog.writeToLogFileDouble("Nominalzins: ", cc);
Writelog.writeToLogFileInt("Laufzeit: ", ee);
Writelog.writeToLogFileDouble("Restschuld: ", rest);
/////////
// Ratenberechnung
double nomzins = (cc/12.0/100.0) + 1.0;
double unten = 0.0;
for (int x = 0 ; x <= ee-1 ; x++)
{
unten = unten + Math.Pow(nomzins,x);
}
double rate = ((aa * Math.Pow(nomzins, ee)) - rest)/unten;
Console.Write("Rate: {0:f2}\n", rate);
int monate = ee;
double[] forward;
double[] backward;
uint bytes = 6 * sizeof(double);
//C++ TO C# CONVERTER TODO TASK: The memory management function 'malloc' has no equivalent in C#:
//forward = (double)malloc(monate * bytes);
forward = (double)(monate * bytes);
//C++ TO C# CONVERTER TODO TASK: The memory management function 'malloc' has no equivalent in C#:
backward = (double)malloc(monate * bytes);
for (int i = 0; i <= monate; i++)
{
forward[i] = 0.0;
backward[i] = rate;
}
forward[0] = auszahlungsbetrag;
backward[0] = 0.0;
backward[monate] = rate + rest;
double ez = Effektivzinssolver.esolver(12, monate, forward, backward);
Console.Write("Effektivzins: {0:f2}\n", ez);
string tmp0 = new string(new char[256]);
tmp0 = string.Format("Rate: {0:f2} ({1:f})", rate, rate);
Writelog.writeToLogFile(tmp0);
string tmp = new string(new char[256]);
tmp = string.Format("Effektivzins: {0:f2} ({1:f})", ez, ez);
Writelog.writeToLogFile(tmp);
//C++ TO C# CONVERTER TODO TASK: The memory management function 'free' has no equivalent in C#:
free(forward);
//C++ TO C# CONVERTER TODO TASK: The memory management function 'free' has no equivalent in C#:
free(backward);
}
}
}
這不是C++代碼,那是C代碼。 – Angew
@Angew這並不是說這裏的代碼不是有效的C++。爲什麼,我一直認爲「C++」是指整個語言,而不僅僅是那些不在經典C中的部分。 – user3109672
@ user3109672 OK,是的。但是,將慣用的C++代碼轉換爲C#將遵循一個完全不同的過程,即將此「C與新奇文件擴展名」代碼轉換爲C#。 – Angew