我需要找到一個代碼,以便我可以從列表框中最小的數字中減去最大的數字。我添加列表框中的項目從屬性,如果有人知道什麼,請幫助我,我試過這個代碼如何計算列表框中的兩個數字
int lowestattendance = attenadances.Max();
string lowestname = "";
int index = 0;
while (index < attenadances.Count) ;
{
if (attenadances[index] < lowestattendance)
{
lowestattendance = attenadances[index];
lowestname = Names[index];
}
index++;
}
string message = string.Format(
"the person with the lowest attendance is {0}" + "and his attendance is { 1}",
lowestname,
lowestattendance);
MessageBox.Show(message, " lowest attendance");
而且也從未表現出任何東西。
您是否調試過您的代碼以查看發生了什麼?當你說「它從未展示過任何東西」時,你的意思是沒有出現信息框,或者它沒有顯示你認爲的信息? –
'attenadances'是什麼?它是列表框控件的名稱嗎? – RBT