I have this class:
class Salaries : IEnumerable
{
List<double> salaries = new List<double>();
public Salaries()
{
}
public void Insert(double salary)
{
salaries.Add(salary);
}
public IEnumerator GetEnumerator()
{
return salaries.GetEnumerator();
}
}
In the program I try to add some values like this:
Salaries mySalaries = new Salaries() { 1000, 2000, 3000 };
I get this error:
'Salaries' does not contain a definition for 'Add' and no extension method 'Add' accepting a first argument of type 'Salaries' could be found (are you missing a using directive or an assembly reference?)
Why do I get this error?
Where can I find (using VS) that I need to implement Add
function?
If I look in the List definition, I can see more functions, so why the compiler wants me to implement Add
?
(I know that if I change the method in the class from Insert to Add it's OK. But the question is why only add, and where does it come from?)