Reputation: 74
I've searched a few topics about this but I'm still stuck, I'm fairly new to c# and this error is starting to give me a headache. I'm trying to Initilise a list but i keep getting that error message. Any help is very welcome.
public static List<BookOperator> CreateBookOperators()
{
List<BookOperator> ops = new List<BookOperator>();
BookOperator op = new BookOperator(ops);
ops.Add(op);
return ops;
}
Upvotes: 3
Views: 9948
Reputation: 400
If the BookOperator object need to know its owner then the BookOperator needs at least 1 argument in its constructor.
public class BookOperator
{
public List<BookOperator> BookOperators { get; private set; }
public BookOperator(List<BookOperator> bookOperators)
{
BookOperators = bookOperators;
}
}
Upvotes: 2
Reputation: 1062780
It looks to me like there is no reason to try and pass the list to the book-operator. Even money says:
public static List<BookOperator> CreateBookOperators()
{
List<BookOperator> ops = new List<BookOperator>();
BookOperator op = new BookOperator();
ops.Add(op);
return ops;
}
or more tersely:
public static List<BookOperator> CreateBookOperators() {
return new List<BookOperator> {
new BookOperator()
};
}
Upvotes: 1
Reputation: 32681
it means that your class BookOperator
doesn't have any constructor that is taking one arguement. if you can show the code for BookOperator it would be helpful. I guess you need this, i am saying so because your current code doesn't makes any sense. You are passing list as a parameter to class and adding your same class to list. Loop doesn't makes sense to me
BookOperator op = new BookOperator();
ops.Add(op)
Upvotes: 5