📄 base.cs
字号:
using System;
using System.Collections;
namespace NSLinearProgramming
{
public class CStandardElement : IDisposable
{
#region IDisposable 成员
public virtual void Dispose()
{
}
#endregion
}
/// <summary>
/// 集合泛型类
/// </summary>
/// <typeparam name="Element">集合中的元素,要求是class,实现IDisposable接口</typeparam>
public class CStandardCollection<Element> : ICollection, IEnumerable, IDisposable where Element : CStandardElement
{
protected ArrayList m_aList;
public CStandardCollection()
{
m_aList = new ArrayList();
}
public CStandardCollection(int iCout)
{
m_aList = new ArrayList(iCout);
}
#region ICollection 成员
public bool IsSynchronized
{
get
{
return this.m_aList.IsSynchronized;
}
}
public int Count
{
get
{
return this.m_aList.Count;
}
}
public void CopyTo(Array array, int index)
{
m_aList.CopyTo(array, index);
}
public object SyncRoot
{
get
{
return this.m_aList.SyncRoot;
}
}
#endregion
#region IEnumerable 成员
public System.Collections.IEnumerator GetEnumerator()
{
return m_aList.GetEnumerator();
}
#endregion
#region 索引器及增删等操作
/// <summary>
/// 索引器
/// </summary>
public Element this[int index]
{
get
{
System.Diagnostics.Debug.Assert(index >= 0 && index < this.m_aList.Count);
return this.m_aList[index] as Element;
}
}
public void Add(Element t)
{
m_aList.Add(t);
}
public void Remove(Element t)
{
int index = this.IndexOf(t);
if (index != -1)
this._RemoveAt(index);
}
public void RemoveAt(int index)
{
if (index > this.Count || index < 0)
return;
_RemoveAt(index);
}
private void _RemoveAt(int index)
{
Element t = this[index];
m_aList.RemoveAt(index);
t.Dispose();
t = null;
}
public bool Contains(Element t)
{
return m_aList.Contains(t);
}
public int IndexOf(Element t)
{
return m_aList.IndexOf(t);
}
public void Clear()
{
for (int i = 0; i < this.m_aList.Count; i++)
{
this._RemoveAt(i);
}
m_aList.Clear();
}
#region IDisposable 成员
public virtual void Dispose()
{
this.Clear();
m_aList = null;
}
#endregion
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -