我的程序有文本框和列表视图,信息被输入文本框,然后单击按钮显示到列表视图中。信息是身份证、名字、姓氏和年薪。信息存储在数组中。
我想找到薪水最低的人。我该怎么做呢?(在 C# 中)
这是我的 Form1:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace Employee_Program
{
public partial class Form1 : Form
{
public Form1()
{
em = new ArrayList();
InitializeComponent();
}
public ArrayList em = new ArrayList();
private void show_employee()
{
listView1.Items.Clear();
foreach(Employee a in em)
{
int i = listView1.Items.Count;
listView1.Items.Add(a.EmployeeId.ToString());
listView1.Items[i].SubItems.Add(a.FirstName);
listView1.Items[i].SubItems.Add(a.LastName);
listView1.Items[i].SubItems.Add(a.YearSalary.ToString());
}
}
private void button1_Click(object sender, EventArgs e)
{
Employee a = new Employee();
a.EmployeeId = float.Parse(employeeId.Text);
a.FirstName = firstName.Text;
a.LastName = lastName.Text;
a.YearSalary = float.Parse(yearSalary.Text);
em.Add(a);
show_employee();
}
private void button2_Click(object sender, EventArgs e)
{
// this is the button that will return the lowest salary value. Preferably in a
//message box? Any idea?
}
}}
这是我的班级,员工:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Employee_Program
{
class Employee
{
protected float employeeId;
protected string firstName;
protected string lastName;
protected float yearSalary;
// first constructor
public Employee()
{
employeeId = 0;
firstName = "";
lastName = "";
yearSalary = 0;
}
// second constructor
public Employee(float EmployeeId, string FirstName,
string LastName, float YearSalary)
{
employeeId = EmployeeId;
firstName = FirstName;
lastName = LastName;
yearSalary = YearSalary;
}
public float EmployeeId
{
get
{
return employeeId;
}
set
{
employeeId = value;
}
}
public string FirstName
{
get
{
return firstName;
}
set
{
firstName = value;
}
}
public string LastName
{
get
{
return lastName;
}
set
{
lastName = value;
}
}
public float YearSalary
{
get
{
return yearSalary;
}
set
{
yearSalary = value;
}
}
}
}