C#2.0范型---资源库模式
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
for (int i = 0; i < 100; i++)
{
Repository<Foo>.Instance.Add(new Foo(i));
}
Console.WriteLine(Repository<Foo>.Instance[9].Count);
Console.ReadLine();
}
}
public class Repository<T>
{
private static Repository<T> _instance;
private ArrayList _list;
public Repository()
{
_list = new ArrayList();
}
public static Repository<T> Instance
{
get
{
if (_instance == null)
_instance = new Repository<T>();
return _instance;
}
}
public T this[int index]
{
get
{
return (T)_list[index];
}
}
public int Add(T t)
{
return _list.Add(t);
}

}
partial class Foo
{
private int _count = 0;
public Foo(int count)
{
_count = count;
}
public string Count
{
get
{
return _count.ToString();
}
}
}
}


浙公网安备 33010602011771号