List generics can be converted to an array
The same point for list generics and arrays: The data type of the list generic must be specified, and the data type of the array must also be specified. List generics and the difference between arrays: the length of the list generic is arbitrary, and the length of the array must be specified at the time of declaration.
Because the type of the list generic collection is unique, the list generic collection can be converted to an array of arrays. The list generic collection can be converted to what type of the set depends on what type of List generic collection is.
Most common methods for list generic collections and ArrayList are consistent. The list generic collection sample code:
namespace _09.List泛型集合
{
class Program
{
static void Main(string[] args)
{
//创建泛型集合对象
List<int> list = new List<int>(); //创建了一个整型的泛型集合
list.Add(1);
list.Add(2);
list.Add(3);
list addrange ( new int Span class= "pun" >[] { 4 5 6 7 8 9 0
foreach (var item in list)
{
Console.WriteLine(item);
}
Console.WriteLine("====================================");
//将List泛型集合转换成数组
int[] lArray=list.ToArray();
for (int i = 0; i < lArray.Length; i++)
{
Console.WriteLine(lArray[i]);
}
Console.WriteLine("====================================");
//将整型数组转换成泛型集合
List<int> listTwo=lArray.ToList();
for (int i = 0; i < listTwo.Count; i++)
{
Console.WriteLine(listTwo[i]);
}
Console.ReadKey();
}
}
}
From for notes (Wiz)
02.List Generic Collection