構造方法#region 構造方法
//類型構造器
static ReversibleSortedList()
{
ReversibleSortedList<TKey, TValue>.emptyKeys = new TKey[0];
ReversibleSortedList<TKey, TValue>.emptyValues = new TValue[0];
}
//無參構造方法
public ReversibleSortedList()
{
this.keys = ReversibleSortedList<TKey, TValue>.emptyKeys;
this.values = ReversibleSortedList<TKey, TValue>.emptyValues;
this._size = 0;
this._sortDirectionComparer = new SortDirectionComparer<TKey>();
this._currentSortDirection = this._sortDirectionComparer.SortDirection;
}
//用於指定排序方向的構造方法
public ReversibleSortedList(SortDirectionComparer<TKey> comparer)
: this()
{
if (comparer != null)
{
this._sortDirectionComparer = comparer;
this._currentSortDirection = _sortDirectionComparer.SortDirection;
}
}
//用於指定字典的構造方法
public ReversibleSortedList(IDictionary<TKey, TValue> dictionary)
: this(dictionary, (SortDirectionComparer<TKey>)null)
{
}
//用於指定列表容量的構造方法
public ReversibleSortedList(int capacity)
{
if (capacity < 0)
{
throw new ArgumentOutOfRangeException(
"capacity", "Non-negative number required");
}
this.keys = new TKey[capacity];
this.values = new TValue[capacity];
this._sortDirectionComparer = new SortDirectionComparer<TKey>();
this._currentSortDirection = _sortDirectionComparer.SortDirection;
}
//用於指定字典和排序方向的構造方法
public ReversibleSortedList(IDictionary<TKey, TValue> dictionary,
SortDirectionComparer<TKey> comparer)
: this((dictionary != null) ? dictionary.Count : 0, comparer)
{
if (dictionary == null)
{
throw new ArgumentNullException("dictionary");
}
dictionary.Keys.CopyTo(this.keys, 0);
dictionary.Values.CopyTo(this.values, 0);
Array.Sort<TKey, TValue>(this.keys, this.values,
this._sortDirectionComparer);
this._size = dictionary.Count;
}
//用於指定容量和排序方向的構造方法
public ReversibleSortedList(int capacity, SortDirectionComparer<TKey> comparer)
: this(comparer)
{
this.Capacity = capacity;
}
#endregion //CTORS