Consider we are having a class as show below
public class Hotel
{
public List<Room> lstRooms;
public List<Room> objLstRoom = new List<Room>();
}
If I create an object for this Hotel class,
- What would be the difference between these two variables in that object?
- Since list would be empty initially, what would have been stored in it?
lstRoomsWill be null,objLstRoomwill be an emptyList<Room>, no elements.This means for example, that
lstRooms.Add(new Room())will throw a null reference exception,objLstRoom.Add(new Room)will just work.