0

Looking these posts:

Does a List<T> guarantee that items will be returned in the order they were added?

Does List<T> guarantee insertion order?

is pretty clear for me that the Add method do an ordered insertion. Perfect.

But my question is: when I use the inline initialization, like this:

var l = new List<object> {
    object1,
    object2,
    object3,
    object4,
};

is the same, right?

Yes, is a silly question, but I can not find anything on MSDN.

Community
  • 1
  • 1
Gioce90
  • 551
  • 2
  • 9
  • 29
  • 4
    A collection initializer gets compiled to `Add()` calls, in the order specified. So put two and two together. And no, I'm not downvoting here. – CodeCaster May 18 '17 at 12:28
  • 1
    *"is a silly question"* - indeed, since list items can be accessed by index, why wouldn't list initializer ensure the order? – Sinatr May 18 '17 at 12:44

0 Answers0