我正在研究一個需要顯示高於平均收入的人員列表的項目。源數據是List<IncomeData>
(id
是人的唯一ID):如何在消息框中顯示列表中的項目?
public struct IncomeData
{
public string id;
public double household;
public income;
}
public double belowAverage = 0, total, belowAveragePercent;
IncomeData surveyStruct;
List<IncomeData> surveyList = new List<IncomeData>();
List<string> aboveAverage = new List<string>();
這是我如何判斷一個人有平均收入以上。如果一個人平均收入之上,我從surveyStruct
的臨時實例添加id
和income
爲字符串值的高於平均水平的名單:
//Determine poverty.
if (surveyStruct.income - 3480 * surveyStruct.household <= 6730)
{
belowAverage += 1;
}
else if (surveyStruct.income - 3480 * surveyStruct.household >= 6730)
{
aboveAverage.Add(surveyStruct.id);
aboveAverage.Add(surveyStruct.income.ToString());
}
這裏是顯示所需信息的消息中碼框。 (該aboveAverage
列表在這裏添加了。)
private void reportsToolStripMenuItem_Click(object sender, EventArgs e)
{
//Display reports 1, 2, and 3.
MessageBox.Show("Your Entry:\nID Code: " + surveyStruct.id +
"\nHousehold: " + surveyStruct.household.ToString() +
" people\nIncome: " + surveyStruct.income.ToString("C") +
"\n\nPeople Above Average:\n" + aboveAverage +
"\n\nAnd " + belowAveragePercent + "% of people are below average.");
}
現在,這裏的問題:,而不是在消息框中的值的看到一個名單,我看到System.Collections.Generic.List
` 1[System.String]
,其中ID和上述平均人的收入應該是。有人可以告訴我我做錯了什麼,以及如何在消息框中顯示列表值?
@Hogan難道是不同的,如果我使用LINQ的? –
@ chotto-motto - 只有一行! – Hogan