如何可以添加多個數據,而無需添加相同的數據? 我試圖糾正它。如何在不添加相同數據的情況下添加多個數據?
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