As OriginalGriff has indicated it is a bit difficult to try and figure out what you're trying to achieve. So I'll take a guess...
For this answer, I'm going to use an example to illustrate what I believe what you're trying to achieve using mock data.
1. We generate the index for the items before they are grouped
2. Group the indexed list
3. Search the group and flatten back to a single result holding the group key and the index of the item.
class Program
{
static void Main()
{
var actors = new List<Person>
{
new Person() {Name = "Gilligan", Sex = "male"},
new Person() {Name = "The Skipper", Sex = "male"},
new Person() {Name = "Thurston Howell, III ", Sex = "male"},
new Person() {Name = "Mrs. Howell", Sex = "female"},
new Person() {Name = "Ginger Grant", Sex = "female"},
new Person() {Name = "Professor", Sex = "male"},
new Person() {Name = "Mary Ann Summers ", Sex = "female"},
};
var name1 = "Ginger Grant";
var indexedActors = actors.Select((x, i) => new {Index = i, Actor = x});
var result1 = indexedActors
.FirstOrDefault(x => x.Actor.Name.Equals(name1));
var index1 = result1?.Index ?? 0;
var groupedActors = indexedActors.GroupBy(x => x.Actor.Sex);
var result2 = groupedActors
.Select(x => new
{
key = x.Key,
value = x.FirstOrDefault(y => y.Actor.Name.Equals(name1))
})
.Where(x => x.value != null);
var index2 = result2?.Select(x => x.value.Index).FirstOrDefault() ?? 0;
var key = result2?.Select(x => x.key).FirstOrDefault() ?? "";
}
}
class Person
{
public string Name { get; set; }
public string Sex { get; set; }
}
This answer is designed to return only the first result. You will need to modify if you require a list of results.