0

In c#

I am trying to make a simple program that will have a few functions such as adding and deleting members from a roster, search for a member, and display the current # of members. This will later be built upon for more options, and saving the members to a file so it can actually be used over time. For now I just wanted the general layout setup before I even bothered with learning how to save the arrays to a file.

Now my question is: When the user chooses to create a new member for the roster it sends it to a function that will create a new employee with an array that will store Name and Division (just basic info for the test program). How would I create a multidimensional array without declaring how many rows it would need? I can not guess the amount of members due to eventual growth and reduction.

tl:dr Creating roster test program. How do I create a multidimensional array that would have a function add another row to it when a new member joins?

4

1 回答 1

1

数组不可调整大小,您希望使用List<List<T>>whereT是您希望存储的值的类型。

但是,您不一定希望将属性存储在数组中,您确实希望使用类。

public class Employee {
  public string Name {get;set;}
  public string Division {get;set;}
}

然后有一个员工列表

var roster = new List<Employee>();

添加新员工

roster.Add(new Employee { Name = "Mr Tiddles", Division = "Feline" });
于 2013-08-14T09:21:06.097 回答