我创建了一个名为 employees 的类来保存员工信息。该类如下所示。
class Employee
{
private int employeeID;
private string firstName;
private string lastName;
private bool eligibleOT;
private int positionID;
private string positionName;
private ArrayList arrPhone;
private ArrayList arrSector;
如您所见,我创建了一个名为 arrSector 的数组。它采用与员工相关联的部门的名称。现在我还想将扇区 ID 与扇区名称一起使用。
我的问题是如何在单个数组列表变量中实现扇区 ID 和扇区名称。
我想将扇区 ID 的值和扇区名称一起存储。
任何帮助表示赞赏。
最佳答案
创建一个对象来保存这两条信息。
public class Sector
{
public string Name { get; set; }
public int Id { get; set; }
}
然后使用通用列表而不是 ArrayList。
class Employee
{
private int employeeID;
private string firstName;
private string lastName;
private bool eligibleOT;
private int positionID;
private string positionName;
private ArrayList arrPhone;
private List<Sector> arrSector;
}
关于c# - C# 中的数组列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1681161/