当前位置:主页 > 软件编程 > .NET代码 >

C#使用List类实现动态变长数组的方法

时间:2021-07-20 08:53:08 | 栏目:.NET代码 | 点击:

本文实例讲述了C#使用List类实现动态变长数组的方法。分享给大家供大家参考。具体如下:

C#中的list可以当做数组使用,而且无需定义长度,完全是动态的

class Person
{
 public string Name { get; set; }
 public string Address { get; set; }
}
static void Main(string[] args)
{
 List<Person> people = new List<Person>();
 people.Add(new Person()
 {
  Name = "kaka",
  Address = "22,2nd cross,bangalore"
  });
  //no casting needed
  Person p = people[0];
}

希望本文所述对大家的C#程序设计有所帮助。

您可能感兴趣的文章:

相关文章