TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
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?
Reply
Answers (
9
)
Search in directory
Object reference not set to an instance of an object.