软件编程
位置:首页>> 软件编程>> C#编程>> C#使用List类实现动态变长数组的方法

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

作者:令狐不聪  发布时间:2022-11-30 03:44:35 

标签:C#,List,数组

本文实例讲述了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#程序设计有所帮助。

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com