C# - I need to assign the property "name" of the objects in "myPersons" list to the objects of "myBooks" list

  • Thread starter Thread starter Gab12345
  • Start date Start date
G

Gab12345

Guest
  1. class Book {public string Titel;}
  2. class Novel : Book { }
  3. class ComicBook : Book { }
  4. list <Book> myBooks = new list<Book>(){
  5. new Novel {Titel="HP 1"},
  6. new Novel {Titel="HP2"},
  7. new Novel {Titel="HP3"},
  8. new ComicBook {Titel="Naruto"},
  9. new ComicBook {Titel="Naruto2"}
  10. }
  11. class Person {public string Name;}
  12. class Author : Person { }
  13. class Artist : Person { }
  14. List<Person> myPersons = new list(){
  15. new Author {Name = JK.Rawling}
  16. new Artist {Name = Masashi Kishimoto} }

I need to assign the property "Name = JK.Rawling" to some objects of "myBooks" list and "Name = Masashi Kishimoto" to other objects of "myBooks" list in order to have:

obj1 Novel {Titel = "HP1", Author.Name = JK.Rawling}
obj2 Novel {Titel = "HP2", Author.Name = JK.Rawling}
obj3 Novel {Titel = "HP3", Author.Name = JK.Rawling}
obj4 ComicBook {Titel = "Naruto", Artist.Name = Masashi Kishimoto}
obj5 ComicBook {Titel = "Naruto2", Artist.Name = Masashi Kishimoto}


Continue reading...
 
Back
Top