You can initialize an array like this:
int [ ] arr = { 1, 2, 3, 4, 5 };
but List<T>
doesn't allow this:
List<int> list = { 1, 2, 3, 4, 5 };
What's the reason behind this?
After all both allow this:
int [ ] arr = new int [ ] { 1, 2, 3, 4, 5 };
List<int> list = new List<int> { 1, 2, 3, 4, 5 };
Also why it's not possible to do this with a LinkedList<T>
?:
LinkedList<int> ll = new LinkedList<int>() { 1, 2, 3 };
Update
Thanks guys. Just saw the replies. I wanted to pick several answers but it didn't let me so.
Why does the LinkedList has an Add method though explicit implementation? Will this likely be fixed? Because problems like this will just snowball into bigger ones when they are overlooked, right?
Thanks.