marcelo presto

marcelo presto

  • NA
  • 7
  • 1.3k

How to create a list of list of different classes?

Oct 15 2017 4:38 PM
Hello friends!
I'm newbie in c# and I have in my project two classes: User and Entity. I want to create a List of List of these classes. Bellow what i tried.
  1. List<User> lu =newList<User>();List<Entity> le =newList<Entity>();  
  2.   
  3. User a =newUser();  
  4. User b =newUser();  
  5. User c =newUser();  
  6. User d =newUser();  
  7.   
  8. Entity w =newEntity();  
  9. Entity x =newEntity();  
  10. Entity y =newEntity();  
  11. Entity z =newEntity();  
  12.   
  13. lu.Add(a);  
  14. lu.Add(b);  
  15. lu.Add(c);  
  16. lu.Add(d);  
  17.   
  18. le.Add(w);  
  19. le.Add(x);  
  20. le.Add(y);  
  21. le.Add(z);  
  22.   
  23. //This part dont work!  
  24. List<List<dynamic>> l =newList<List<dynamic>>();  
  25. l.Add(lu);l.Add(le);  
To show this list:
  1. foreach(var p inViewBag.usrs)  
  2. {  
  3.     <tr>  
  4.         <td>@p.Name</td>  
  5.         <td>@p.LasName</td>  
  6.     </tr>  
  7. }  
 How can i do that? Create and show a List of List of different objects?

Answers (1)