简体   繁体   中英

C# Having a multi-dimensional list for a staff member

I am looking to set up an employee list to insert multiple items of data. For example, I want to give an employee an ID, Name, and a list of technology skills and a list of personal skills. Not all employees would have the same amount of technology skills or personal skills but have the ability to have multiples of each

So an example would be:

employeeID, employeeName, techSkill1, techSkill2, persSkill1

employeeID, employeeName, techSkill1, persSkill1, persSkill2

employeeID, employeeName, techSkill1, techSkill2, techSkill3, persSkill1

Is this even possible?

Use class:

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);
    }
}

Usage:

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" }));

Yes, this is possible, you can do something like this:

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; }
}

PS Use the solution of @General-Doomer, it's a better solution, but i'll leave my answer here, maybe you can do something with it/learn from it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM