Peter
Peter

Reputation: 761

Get item in the loop in List<T>

I want to select surname of each user in the loop and display it in the textblock, but I'm getting this: System.Linq.Enumerable+WhereSelectListIterator2[PhoneApp1.ServiceREference1.Point,System.String]. How can I correct it?

My WP code is:

foreach (ServiceReference1.Point o in someList)
{
    var text = new TextBlock
    {
        Text = someList.Select(x => x.surnm).ToString(),
        Foreground = new SolidColorBrush(Colors.Orange),
    };
}

Upvotes: 0

Views: 86

Answers (2)

Tim Schmelter
Tim Schmelter

Reputation: 460168

You are already in the loop and have the reference to the current object, so i see no reason for your LINQ query. This should work(presuming that ServiceReference1.Point has a surnm):

foreach (ServiceReference1.Point o in someList)
{
    var text = new TextBlock
    {
        Text = o.surnm.ToString(),
        Foreground = new SolidColorBrush(Colors.Orange),
    };
}

Upvotes: 4

Selman Genç
Selman Genç

Reputation: 101701

Use string.Join

Text = string.Join(Environment.NewLine, someList.Select(x => x.surnme)),

Upvotes: 0

Related Questions