從一個文本框解析爲int,涉足incrementHour方法如圖所示工作。C#輸入字符串的不正確的格式
if (txtHourPlus.Text != String.Empty)
{
time1.incrementHour(int.Parse(txtHour.Text));
}
而在時間類:(該時間1對象類)
public int incrementHour(int step)
{
if (step > 0 && hour < 24)
{
//step = step % hour;
hour = (hour + step) % 24;
time.AddHours(hour);
return hour;
}//end of if
else
{
MessageBox.Show("Please enter a positive number.");
return 0;
}//end of else
}//end of incrementHour
不知道爲什麼我得到這個錯誤。我將它轉換爲corrent數據類型。因爲它接受一個int變量。
好吧好吧,我得到它的取值(小失誤>>根本不想說了吧) 但是有人已經說的方法可能需要的工作,因爲我試圖改變日期時間值,我在第一時間拿到並添加一個小時或減去和等等等等
txtHour.Text不是一個有效的int。達達! – Will 2011-01-28 22:11:02
你可以發佈堆棧跟蹤嗎?我假設錯誤來自`int.parse`。 – 2011-01-28 22:11:42
,你應該更喜歡使用String.IsNullOrWhite空間,而不是比較的String.Empty :) – 2011-01-28 22:13:21