using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace ListDemo
{
class Program
{
static void Main(string[] args)
{
//泛型集合的基本使用
List<int> scoreList = new List<int>();
scoreList.Add();
scoreList.Add();
scoreList.Add();
scoreList.Add();
scoreList.Add();
//List<string> nameList = new List<string>();
scoreList.Insert(, );
//获取元素总数
Console.WriteLine("获取元素总数:"+scoreList.Count );
Console.WriteLine("_________________");
//Console.ReadLine();
//遍历集合
Console.WriteLine("遍历输出在第一种方法:");
foreach (int score in scoreList)
{
Console.WriteLine(score);
}
Console.WriteLine("_________________");
Console.WriteLine("遍历输出在第二种方法:");
for (int i = ; i < scoreList.Count; i++)
{
Console.WriteLine(scoreList[i]);
}
//删除一个元素
Console.WriteLine("_________________");
Console.WriteLine(" 删除一个元素");
scoreList.Remove();
scoreList.Remove();
for (int i = ; i < scoreList.Count; i++)
{
Console.WriteLine(scoreList[i]);
}
Console.WriteLine("_________________");
Console.WriteLine("清除所有元素");
scoreList.Clear();
Console.WriteLine("获取元素总数:" + scoreList.Count);
Console.ReadLine();
}
}
}
运行结果: