Shoaib Ahmed

Shoaib Ahmed

  • NA
  • 189
  • 5.3k

How to create a List of object into a user defined class

Jan 8 2019 3:10 AM
My first class :
 
public class Person
{
public string name{get; set;}
public int Id{get; set;}
 
public list<Company> companies {get; set;} 
 
}
I want to list of companies the person been.  
 
Company Class:
 
public class Company
{
public string name{get; set;}
public string address{get; set; }
 
In Controller I am assigning the list:
List<Person> personList = new List<Person>();
 
I am returning this personlist to the view.
 
How can I create list of user defined type within a user defined class and  How can I show A person multiple companies? 
 
 

Answers (5)