I've made a class called Serie, it's basically a List. How do I make it so that I can make a serie like this; "Serie S = new Serie() { 1, 2, 3, 4 }" like you can do with a List?
class Serie
{
public List<decimal> Serie_ { get; set; }
public decimal this[int index]
{
get
{
return Serie_[index];
}
set
{
Serie_.Insert(index, value);
}
}
public Serie()
{
}
public Serie(List<decimal> serie)
{
Serie_ = serie;
}
public Serie Add(decimal Value)
{
List<decimal> lst = new List<decimal>();
for (int i = 0; i < Serie_.Count; i++)
{
lst.Add(Serie_[i]);
}
lst.Add(Value);
Serie S = new Serie(lst);
return S;
}
public double Count()
{
return Serie_.Count;
}
public static Serie operator +(Serie left, decimal right)
{
List<decimal> temp = new List<decimal>();
for (int i = 0; i < left.Count(); i++)
{
temp.Add(left[i] + right);
}
return new Serie(temp);
}
}
When trying to do so I get the error-message;
Cannot initialize type '' with a collection initializer because it does not implement 'System.Collections.IEnumerable'
I do not know how to do so tho.