score:11

Accepted answer

you are using selectmany, which means project the individual items of another enumerable of enumerables. company.name i presume is a string, which is a collection of chars.

you probably want to just use select given your expectations.

score:3

there were a few other answers, but i thought i'd include an explanation.

if you look at the msdn definition of a string, you'll see that it is implemented as an ienumerable<char>:

[serializableattribute]
[comvisibleattribute(true)]
public sealed class string : icomparable, 
    icloneable, iconvertible, icomparable<string>, ienumerable<char>, 
    ienumerable, iequatable<string>

then, compare that to the definiton of selectmany:

projects each element of a sequence to an ienumerable and flattens the resulting sequences into one sequence

(there's a pretty good visual explanation here: http://www.codethinked.com/a-visual-look-at-the-linq-selectmany-operator)

since the selectmany will treat the string as an ienumerable<char> object, we can infer that the resulting collection from .selectmany(x => x.name) will be an ienumerable<char> made up of all of the characters contained within name.

so, in this case, since you're really only looking for all of the name strings contained within your a.charge.company objects, you really just need to use select:

var companynamelist = prop.chargeitems.select(a => a.charge.company.name).tolist();

score:4

this is because of selectmany, you need probably select here.

selectmany: projects each element of a sequence to an ienumerable and flattens the resulting sequences into one sequence.

so executing selectmany you get ienumerable<char>, after you call tolist(), which projects it to a list<char>


Related Query

More Query from same tag