using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
namespace tryCollectionClass
{
public class Students
{
private int studentID;
private string studentName;
public int ID
{
get
{
return studentID;
}
}
public string name
{
get
{
return studentName;
}
}
public Students(int id, string name)
{
this.studentID = id;
this.studentName = name;
}
}
class Program
{
static void Main(string[] args)
{
Collection<Students> studentCollection = new Collection<Students>();
Students stu1 = new Students(8503, "James");
Students stu2 = new Students(8518, "Allbort");
Students stu3 = new Students(8524, "YouGoFirst");
Students stu4 = new Students(8537, "WeFinished");
Students stu5 = new Students(8519, "ILikeIt");
studentCollection.Add(stu1);
studentCollection.Add(stu2);
studentCollection.Add(stu3);
studentCollection.Add(stu4);
studentCollection.Add(stu5);
foreach (Students s in studentCollection)
{
Console.WriteLine("{0} {1}", s.name, s.ID);
}
Console.WriteLine();
Console.WriteLine(studentCollection.Count());
//Console.ReadKey();
studentCollection.Clear();
Console.WriteLine("Clear");
Console.WriteLine(studentCollection.Count());
Console.ReadKey();
}
}
}
/*
James 8503
Allbort 8518
YouGoFirst 8524
WeFinished 8537
ILikeIt 8519
5
Clear
0
请按任意键继续. . .
*/