tags:

views:

30

answers:

3

Hi,

i have a list with objects. The object has a property 'Sales' which is a string. Now i want to create a list of doubles with the values of all objects' 'Sales' properties.

I tried this: var tmp = from n in e.Result select new{ Convert.ToDouble ( n.Sales) };

but this gives me this error:

Error 106 Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment, simple name or member access.

EDIT: first i tried it without the Convert, but then i have a list of anonymous types (not strings) and i couldn't get that converted to a list fo doubles either....

+2  A: 

Change your code to this:

var tmp = from n in e.Result select new{Value = Convert.ToDouble ( n.Sales) };

You need to define a property name for the anon type: i.e. "Value = blah"

Andras Zoltan
thanks, didn't know about the property name
Michel
+1  A: 

Try this:

var tmp = from n in e.Result select new{ Sales = Convert.ToDouble ( n.Sales) };
David Neale
+4  A: 

The following will give you a list of doubles.

List<double> listOfDoubles = (from n in e.Result
                              select Convert.ToDouble(n.Sales)).ToList();
Daniel Renshaw