Could someone provide me a small example on how to Use the .NET 6 LINQ IntersectBy
and ExceptBy
methods? MSDN hasn't got any examples and the one I tried doesn't compile due to CS0411 error. The example I tried:
namespace Test
{
internal struct Example
{
public int X { get; set; }
public int Y { get; set; }
public override string ToString()
{
return $"{X}, {Y}";
}
}
public class Program
{
public static void Main()
{
var elements = new List<Example>
{
new Example { X = 10, Y = 20 },
new Example { X = 11, Y = 23 },
};
var elements2 = new List<Example>
{
new Example { X = 10, Y = 12 },
new Example { X = 44, Y = 20 },
};
//ok
var union = elements.UnionBy(elements2, x => x.X);
//CS0411 - Why ?
var intersect = elements.IntersectBy(elements2, x => x.X);
//CS0411 - Why ?
var except = elements.ExceptBy(elements2, x => x.X);
Console.ReadKey();
}
}
}