Is there a way using LINQ to get a distinct list of items from a list of object array without knowing how many items exist in each array? The number of items in each array item will be the same throughout the list.
// Foo is a list of object arrays. The number of items
// each array is non-specific.
// (In this example there is only 3 items, but there could be 100)
var foo = new List<object[]>();
// I add some items to the list.
foo.Add(new object[] { 1, "Something", true });
foo.Add(new object[] { 1, "Some Other", false });
foo.Add(new object[] { 2, "Something", false });
foo.Add(new object[] { 2, "Something", false });
// This will get me a distinct list from the array list...
// but it requires I know how many items are in each array.
List<object[]> bar = foo.Select(x => new { X1 = x[0], X2 = x[1], X3 = x[2] })
.Distinct()
.Select(x => new object[] { x.X1, x.X2, x.X3 })
.ToList();
List<object[]> bar = ?? /// < -- How can I rewrite the
// previous line so that
// my code works with n array items?
I will know how many items there are at runtime if that helps?
If it is not possible in LINQ, can anyone please suggest a method I could use to achieve the desired results?