I know LINQ but my knowledge is pretty much only selects, where, orderby and all of the most common functions. Now I have a need to do something that I think is really difficult and
maybe not even possible to do just with LINQ. What I have is a list of people. That’s east
to query but I need to create a text string from that list. The text string has to give a letter followed by the name of each person.
IList<person> Person
I need to be able to have a LINQ statement that checks through the Person list. I need
to be able to look for names that appear more than once. So far I have the following. It works okay but doesn’t give everything needed:
Person[0] name="Fred" &
Person[1] name="Pete" &
Person[2] name="Tony" the var abc = "a) Fred. b) Pete. c) Tony
var a = "";
foreach (var person in _persons
.Select((data, value) => new { Data = data, Value = value })
{
a = a + (char)(details.Value + 64) + details.name
}
What I need is the additional functionality so that:
Person[0] name="John" then var abc = "a) John."
Person[1] name="John" &
Person[3] name="John" then var abc = "b) & d) John."
Person[1] name="John" &
Person[2] name="John" &
Person[3] name="John" then var abc = "b),c) & d) John."
In other words, get the names and put a character before them that shows what position the name is in the list. However if the name appears twice then instead of a)name1. b)name1 I need to get a),b) name.
It’s something I can’t really figure out how to do. I would appreciate any advice or pointers that anyone can give me.
Given:
You can write:
And that gives you: