using System; using System.Collections.Generic; namespace XMainClient { public class XDataPool where T : XDataBase, new() { private static Queue _pool = new Queue(); public static T GetData() { bool flag = XDataPool._pool.Count > 0; T result; if (flag) { T t = XDataPool._pool.Dequeue(); t.Init(); t.bRecycled = false; result = t; } else { T t2 = Activator.CreateInstance(); t2.Init(); t2.bRecycled = false; result = t2; } return result; } public static void Recycle(T data) { bool flag = !data.bRecycled; if (flag) { XDataPool._pool.Enqueue(data); data.bRecycled = true; } } } }