This is my DecimalCollection that i use in my Technical Indicators Library. I would like your comments on this source.
public class DecimalCollection : CollectionBase, IEnumerable<Decimal>, IEnumerator
{
private Int32 _CurrentIndex = 0;
public virtual void AddRange(Decimal[] items)
{
//Rule CA1062
if (items == null) throw new ArgumentNullException("items");
foreach (Decimal item in items)
{
List.Add(item);
}
}
public virtual void AddRange(DecimalCollection items)
{
foreach (Decimal item in items)
{
List.Add(item);
}
}
public virtual void Add(Decimal value)
{
List.Add(value);
}
public virtual Boolean Contains(Decimal value)
{
return List.Contains(value);
}
public virtual Int32 IndexOf(Decimal value)
{
return List.IndexOf(value);
}
public virtual void Insert(Int32 index, Decimal value)
{
List.Insert(index, value);
}
public virtual Decimal this[Int32 index]
{
get { return (Decimal) List[index]; }
set { List[index] = value; }
}
public virtual void Remove(Decimal value)
{
List.Remove(value);
}
private Decimal Sum()
{
Decimal sum = 0m;
for (Int32 i = 0; i < Count; i++)
sum += this[i];
return sum;
}
public virtual Decimal Average()
{
if (Count > 0)
return Sum()/Count;
else
return 0m;
}
#region IEnumerable<Double> Members
IEnumerator<Decimal> IEnumerable<Decimal>.GetEnumerator()
{
foreach (Decimal item in InnerList)
{
yield return item;
}
}
#endregion
#region IEnumerable Members
IEnumerator IEnumerable.GetEnumerator()
{
return this;
}
#endregion
#region IEnumerator Members
public object Current
{
get { return this[_CurrentIndex]; }
}
public Boolean MoveNext()
{
if (_CurrentIndex < Count)
{
_CurrentIndex++;
return true;
}
else
return false;
}
public void Reset()
{
_CurrentIndex = 0;
}
#endregion
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment