【发布时间】:2013-05-31 23:47:13
【问题描述】:
我正在开展一个项目,该项目需要显示收入高于平均水平的人员列表。源数据是 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 和收入应该是。有人可以告诉我我做错了什么以及如何在消息框中显示列表值吗?
【问题讨论】:
标签: c# list struct messagebox