我目前有這個循環的問題。它變成一個無限循環,我得到一個堆棧溢出錯誤。這是針對利率交易互換應用程序的。我是交易的長度,l是增加的指數。帶循環c的堆棧溢出#
private void button1_Click(object sender, EventArgs e)
{
int outp = 0;
int i = int.Parse(tradeLength.Text);
string month = "January";
for (int l = 1; l <= i; l++)
{
Console.WriteLine("I iterated " + l + " Amount of times");
if (l == 1)
{
month = "January";
}
if (l == 2)
{
month = "February";
}
if (l == 3)
{
month = "March";
}
if (l == 4)
{
month = "Aprll";
}
if (l == 5)
{
month = "May";
}
if (l == 6)
{
month = "June";
}
if (l == 7)
{
month = "July";
}
if (l == 8)
{
month = "August";
}
if (l == 9)
{
month = "September";
}
if (l == 10)
{
month = "October";
}
if (l == 11)
{
month = "November";
}
if (l == 12)
{
month = "December";
}
else
{
month = "Null";
l = 1;
}
正如僅供參考,您可以通過使用新的System.Globalization.CultureInfo(「en-US」)獲得一個月的名稱DateTimeFormat.GetMonthName(index)' –
代碼是不完整的,並且問題的原因是最後的其他情況。 – Milster
的代碼你的最後一節是說拋開「如果'l'不是12,將其設置爲1」 – stuartd