I want to sort already sorted list in this manner.
Already Sorted List =
Ali-23423423423
Ali-234234
Ali-234234255
Bali-36365356
Bali-32326546456
Bali-361111
Tali1-234234
Tali2-2342342
Tali3-23424
I am trying to find a query so that I can sort it like this
Ali-12315254
Bali-23346363
Tali-242452345
Ali-2342134134
Bali-234234234
Tali-242342
and So On.
I made a loop for the job but it is very slow and some what problematic as-well. Is there any solution?
while (List1.Count+10 < List.Count)
{
i++;
if (List.ElementAt(i).Remove(List.ElementAt(i).IndexOf('-')) == List1.ElementAt(i + 1).Remove(List1.ElementAt(i + 1).IndexOf('-')))
{
String Element = List.ElementAt(i);
List.RemoveAt(i);
List.Add(Element);
i--;
}
else
{
List1.Add(List.ElementAt(i));
}
}
List = List1;
is the not so good way around I come up with
This query will give you unique items by name
UPDATE I think this code does exactly what you want – only first occurrence of every name is selected first, then second occurrences are selected, etc
Output for your sample data is: