Gavin Draper's Blog

Father, Developer, Tech Geek, Extreme Sports Fanatic

@gavdraper | +gavdraper | github | StackOverflow Careers
 

C# Object Initializers On Lists

I've had a few comments on the Object Initializers I posted about in my previous post namely how to use them for lists.

Well its pretty much the same syntax as for single objects and here it is

  
  Rooms = new List<Room>()
     {
      new Room(){Name="Room 1", Id=1},
      new Room(){Name="Room 2", Id=2},
      new Room(){Name="Room 3", Id=3},
     };

 
comments powered by Disqus