Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / July 2008

Tip: Looking for answers? Try searching our database.

Collection initialisers

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike P - 31 Jul 2008 15:50 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.