我尝试了下面的解决方案,但我不喜欢它。我正在寻找扩展类,而不是封装一个double[]
.
谢谢。
编辑:我们需要使用 .NET 2.0
public class DoubleArray : IList, ICloneable
{
protected double[] items;
/// <summary>
/// Gets the last item in the array.
/// </summary>
public double Last { get { return items[items.Length-1]; } }
/// <summary>
/// Gets the number of items in the array.
/// </summary>
public int Length { get { return items.Length; } }
/// <summary>
/// Number of items constructor.
/// </summary>
/// <param name="len">Number of items</param>
public DoubleArray(int len)
{
items = new double[len];
}
public double this[int index]
{
get { return items[index]; }
set { items[index] = value; }
}
public bool IsReadOnly
{
get { return items.IsReadOnly; }
}
public bool IsFixedSize
{
get { return items.IsFixedSize; }
}
public void CopyTo(Array array, int index)
{
items.CopyTo(array, index);
}
public IEnumerator GetEnumerator()
{
return items.GetEnumerator();
}
public object SyncRoot
{
get { return items.SyncRoot; }
}
public bool IsSynchronized
{
get { return items.IsSynchronized; }
}
object ICloneable.Clone()
{
return items.Clone();
}
#region ICollection and IList members implementation
// hides this members from intellisense, see: http://stackoverflow.com/questions/10110205/how-does-selectedlistviewitemcollection-implement-ilist-but-not-have-add
int ICollection.Count
{
get { return items.Length; }
}
int IList.Add(object value)
{
throw new NotImplementedException();
}
bool IList.Contains(object value)
{
throw new NotImplementedException();
}
void IList.Clear()
{
throw new NotImplementedException();
}
int IList.IndexOf(object value)
{
throw new NotImplementedException();
}
void IList.Insert(int index, object value)
{
throw new NotImplementedException();
}
void IList.Remove(object value)
{
throw new NotImplementedException();
}
void IList.RemoveAt(int index)
{
throw new NotImplementedException();
}
object IList.this[int index]
{
get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); }
}
#endregion
}