Lars Persson

Lars Persson

  • NA
  • 110
  • 0

Save a List of objects in another object.

Apr 13 2012 11:50 AM
I have a Customer-object and a Book-object in a library-system.

When I  register a loan I want the chosen Book-object to be saved to a List-control in  the Customer-object.

The idea is to show all the books a customer have  lended in a richTextBox.

I did this in an old Java-course and I have been  trying to translate it to C#.

In the Customer-Class I have  declared:
private List<Bok> loan;
Have a property that  returns a booklist:
public list<Book>  loan
{
get
{
return loan = new  List<Book>();
}
}  I also instanciates the List in a  constructor.
Then I do this when try to register the  loan:
bookToLend.BiblioteksKund = lender;  //bookToLend is a Book-object.
lender.Loan.Add(bookToLend); //lender is  a Customer-object, loan is a List of Books.

I get  no error but the selected book doesn't seem to be added to the list  in the customer-object. Why? 

Answers (9)