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
You probably want to just use
Select given your expectations.
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.
SelectMany you get
IEnumerable<char>, after you call
ToList(), which projects it to a
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
[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)
SelectMany will treat the
String as an
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
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
var CompanyNameList = Prop.ChargeItems.Select(a => a.Charge.Company.Name).ToList();
- why is my lambda expression being a character?
- Lambda Expression for Many to Many realtionship in C# EF 5 Code First
- How to write the same code using Lambda Expression
- How to write following code in lambda expression or linq?
- ForEach loop with Lambda expression in Razor code MVC 5 For List<T>
- VS Code Coverage won't recognize only possible Expression Lambda Path
- Lambda expression with statement body error in previously working code
- How to insert a record in lambda expression and possible way to shorten the length of code
- Retrieving Property name from lambda expression
- "A lambda expression with a statement body cannot be converted to an expression tree"
- An expression tree lambda may not contain a null propagating operator
- Cannot convert lambda expression to type 'string' because it is not a delegate type
- C# Pass Lambda Expression as Method Parameter
- "Or" equivalent in Linq Where() lambda expression
- Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type
- How to write a VB.Net Lambda expression
- Pass a lambda expression in place of IComparer or IEqualityComparer or any single-method interface?
- LINQ: Passing lambda expression as parameter to be executed and returned by method
- Cannot convert lambda expression to type 'object' because it is not a delegate type
- Can you create a simple 'EqualityComparer<T>' using a lambda expression
- Like in Lambda Expression and LINQ
- What is the Efficiency and Performance of LINQ and Lambda Expression in .Net?
- lambda expression for exists within list
- Can I use Linq's Except() with a lambda expression comparer?
- LINQ: Get all selected values of a CheckBoxList using a Lambda expression
- Expression cannot contain lambda expressions
- Difference between expression lambda and statement lambda
- Lambda expression for multiple parameters
- Simple Examples of joining 2 and 3 table using lambda expression
- ReSharper gives an "@" prefix to a variable name in a lambda expression
- Linq to XML with n number of dynamic where conditions
- Modifying Linq Results
- How to pivot data in LINQ without hard coding columns
- IQueryable type to an Array
- Counting for how many instances a bool property is true - C#
- Linq get distinct ordered elements without .GroupBy()
- How does the EF use the callback provided in the LINQ `Where` function to select elements from DB?
- Grouping on DataTable using LINQ
- Reading a key/value pair to a dictionary by passing the path of the .config file c#
- AsEnumerable and Query Syntax
- Duplicate items when consuming ODATA service
- Filter by Key in a Dictionary within a List of objects?
- Error Inside Of Visual Studio 2012 - " '.' or '(' expected "
- email read from EWS (exchange web service) server cannot process this request error c#
- Filtering Dataset based on similar column values
- Comparing two datasources in C#
- Error while deleting a record with LINQ
- Exclusive use entity from a Product of Query
- Distinct not working with LINQ to Objects
- Sorting a 1-to-many relationship for a log table for the most recent item