如何可以添加多个数据,而无需添加相同的数据? 我试图纠正它。如何在不添加相同数据的情况下添加多个数据?
public partial class SalaryCalculator : Form
{
public SalaryCalculator()
{
InitializeComponent();
}
public Double basicAmount, houseRent, medicalAllowance, totalHouseRent, totalMedicalAllowance, totalSalary;
public int id = 0;
private void addButton_Click(object sender, EventArgs e)
{
ListViewItem newList = new ListViewItem((++id).ToString());
string employeeName = nameTextBox.Text;
double basicAmount = Convert.ToDouble(basicTextBox.Text);
double houseRent = Convert.ToDouble(houseRentTextBox.Text);
double medicalAllowance = Convert.ToDouble(medicalTextBox.Text);
totalHouseRent = (basicAmount*houseRent)/100;
totalMedicalAllowance = (basicAmount*medicalAllowance)/100;
totalSalary = basicAmount + totalHouseRent + totalMedicalAllowance;
totalTextBox.Text = totalSalary.ToString();
newList.SubItems.Add(employeeName);
newList.SubItems.Add(totalSalary.ToString());
listView1.Items.Add(newList);
}
}
}
如何可以添加多个数据,而无需添加相同的数据?
尝试使用HashSet。 http://stackoverflow.com/q/4558754/3956100 – Niklas