CSharp · Console
using System;
using System.Collections.Generic;
using System.Linq;
public class Program
{
class A
{
public int id;
}
class B
{
public int id;
}
public static void Main()
{
var listA = new List<A>() { new A() { id = 4 }, new A() { id = 5 }, new A() { id = 1 } };
var listB = new List<B>() { new B() { id = 1 }, new B() { id = 4 }, new B() { id = 5 } };
Console.WriteLine("listB (before):");
foreach (var b in listB)
Console.WriteLine(b.id);
listB = listB.OrderBy(b => listA.FindIndex(a => a.id == b.id)).ToList();
Console.WriteLine("\nlistB (after):");
foreach (var b in listB)
Console.WriteLine(b.id);
}
}