Linq question

  • Thread starter Thread starter CSharper
  • Start date Start date
C

CSharper

I was following an example of silverlight and I ran into a problem
when I executed the linq

http://www.silverlightshow.net/items/introduction-to-the-datagrid-control-in-silverlight-2.aspx


List<Nutrition> data = ( from nutrition in nutritionsDoc.Descendants
( "Nutrition" )
select new Nutrition
{
Group = nutrition.Attribute
( "Group" ).Value,
Name = nutrition.Attribute
( "Name" ).Value,
Quantity = nutrition.Attribute
( "Quantity" ).Value
} ).ToList();

if I understood correct, I do not need to define the class Nutrition
before hand since it will be treated as anonymous class. But the
compiler fails with Nutrition class reference is missing.

Please correct me if my understanding is wrong.
 
I was following an example of silverlight and I ran into a problem
when I executed the linq

http://www.silverlightshow.net/items/introduction-to-the-datagrid-con...

List<Nutrition> data = ( from nutrition in nutritionsDoc.Descendants
( "Nutrition" )
select new Nutrition
{
Group = nutrition.Attribute
( "Group" ).Value,
Name = nutrition.Attribute
( "Name" ).Value,
Quantity = nutrition.Attribute
( "Quantity" ).Value

} ).ToList();

if I understood correct, I do not need to define the class Nutrition
before hand since it will be treated as anonymous class. But the
compiler fails with Nutrition class reference is missing.

Please correct me if my understanding is wrong.

My bad, it is not anonymous class. I know what I did wrong. Sorry
about it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top