📅  最后修改于: 2020-10-31 04:24:35             🧑  作者: Mango
C#清单
让我们看一个通用列表的例子
using System;
using System.Collections.Generic;
public class ListExample
{
public static void Main(string[] args)
{
// Create a list of strings
var names = new List();
names.Add("Sonoo Jaiswal");
names.Add("Ankit");
names.Add("Peter");
names.Add("Irfan");
// Iterate list element using foreach loop
foreach (var name in names)
{
Console.WriteLine(name);
}
}
}
输出:
Sonoo Jaiswal
Ankit
Peter
Irfan
using System;
using System.Collections.Generic;
public class ListExample
{
public static void Main(string[] args)
{
// Create a list of strings using collection initializer
var names = new List() {"Sonoo", "Vimal", "Ratan", "Love" };
// Iterate through the list.
foreach (var name in names)
{
Console.WriteLine(name);
}
}
}
输出:
Sonoo
Vimal
Ratan
Love