I am working through some LINQ examples on MSDN, and I have come across
some code that doesn't seem to work here :
http://msdn.microsoft.com/en-us/vcsharp/aa336753.aspx
Is this the right way to use collection initialisers or is this way that
I have found on another website correct :
List<Product> productList = new List<Product>
{
new Product
{
ProductID = 1, ProductName = "Chai", Category =
"Beverages", UnitPrice = 18.0000M, UnitsInStock = 39
},
new Product
{
ProductID = 2, ProductName = "Chang", Category =
"Beverages", UnitPrice = 19.0000M, UnitsInStock = 17
},
new Product
{
ProductID = 3, ProductName = "Aniseed Syrup", Category =
"Condiments", UnitPrice = 10.0000M, UnitsInStock = 13
}
Marc Gravell - 31 Jul 2008 16:00 GMT
The MSDN page you cite is wrong.
I would suggest looking at the actual code from the download if it is
still there. The online samples are known to be garbled beyond
recognition in several cases.
So yes, the MSDN code looks borked: there should be a "new" or 1800 in
there... and from the List<product>, I'd guess "new product {...}" each
time, rather than "new {...}" which would be an anon-type. It also
doesn't return the list it creates!
Marc