我希望建立一个雇员列表,以插入多个项目的数据。例如,我希望为一名员工提供ID、姓名、技术技能列表和个人技能列表。并非所有员工都拥有相同数量的技术技能或个人技能,但有能力拥有这两种技能的倍数
因此,举个例子:
employeeID, employeeName, techSkill1, techSkill2, persSkill1
employeeID, employeeName, techSkill1, persSkill1, persSkill2
employeeID, employeeName, techSkill1, techSkill2, techSkill3, persSkill1这有可能吗?
发布于 2015-05-08 15:17:17
使用类:
public class Employee
{
/// <summary>
/// employee's ID
/// </summary>
public int ID { get; set; }
/// <summary>
/// employuee's name
/// </summary>
public string Name { get; set; }
/// <summary>
/// list of personal skills
/// </summary>
public List<string> PersSkills { get; private set; }
/// <summary>
/// list of tecnical skills
/// </summary>
public List<string> TechSkills { get; private set; }
/// <summary>
/// конструктор
/// </summary>
public Employee()
{
this.PersSkills = new List<string>();
this.TechSkills = new List<string>();
}
/// <summary>
/// конструктор
/// </summary>
public Employee(int id, string name, string[] persSkills, string[] techSkills)
{
this.ID = id;
this.Name = name;
this.PersSkills = new List<string>(persSkills);
this.TechSkills = new List<string>(techSkills);
}
}用法:
List<Employee> employees = new List<Employee>();
employees.Add(new Employee(1, "Ivan", new string[] { "good friend" }, new string[] { "engineer" }));
employees.Add(new Employee(2, "Boris", new string[] { "personnel management", "tolerance" }, new string[] { "engineer", "programmer" }));发布于 2015-05-08 15:30:17
是的,这是可能的,你可以这样做:
public List<Member> members = new List<Member>();
public Form1()
{
InitializeComponent();
Member me = new Member();
me.ID = 3;
me.Name = "Maarten";
PersSkill skill1 = new PersSkill();
skill1.Name = "Super Awsome Skill!";
skill1.MoreInfo = "All the info you need";
PersSkill skill2 = new PersSkill();
skill1.Name = "name!";
skill1.MoreInfo = "info";
List<PersSkill> list = new List<PersSkill>();
list.Add(skill1);
list.Add(skill2);
me.PersSkills = list;
}
public struct Member
{
public int ID { get; set; }
public string Name { get; set; }
public List<TechSkill> PersSkills { get; set; }
public List<TechSkill> TechSkills { get; set; }
}
public struct PersSkill
{
public string Name { get; set; }
public string MoreInfo { get; set; }
}
public struct TechSkill
{
public string Name { get; set; }
public string MoreInfo { get; set; }
}附注:使用@General-Doomer的解决方案,这是一个更好的解决方案,但我会在这里留下我的答案,也许你可以用它做点什么/从中学习
https://stackoverflow.com/questions/30117951
复制相似问题