static void Main(string[] args)
{
minlist<authorinfo> aif = new minlist<authorinfo>();
aif.Add(new authorinfo("The Count of Monte Cristo","Alexandre", "Dumas", 1844));
aif.Add(new authorinfo("Rendezvous with Rama", "Arthur", "Clark", 1972));
aif.Add(new authorinfo("The Three Musketeers", "Alexandre", "Dumas", 1844));
aif.Add(new authorinfo("2001: A Space Odyssey", "Arthur", "Clark", 1968));
4项,
class minlist<T>
{
T[] storage = new T[3];
T[] storagereplace = new T[5];
T[] storagereplace2 = new T[10];
int spot = 0;
public void Add(T obj)
{
if (spot != 3)
{
storage[spot] = obj;
spot++;
if (spot == 3)
{
int spot2 = spot;
storage.CopyTo(storagereplace, 0);
storagereplace[spot2] = obj;
spot2++;
foreach (T k in storagereplace)
{
Console.WriteLine(k);
}
Console.WriteLine(spot2);
}
}
结果:
Alexandre,Dumas,基督山伯爵,1844年
亚瑟,克拉克,1972年与拉玛约会,Alexandre,Dumas,The Three Musketeers,1844
Alexandre,Dumas,The Three Musketeers,1844
为什么重复最后一次而不是添加2001?
答案 0 :(得分:3)