CSharp · Console
using System;
using System.Collections.Generic;
using System.Linq;
public class Program
{
public class A
{
public string Id { get; set; }
public string Name { get; set; }
}
public class B
{
public string Id { get; set; }
public string Location { get; set; }
}
public class AB
{
public string Id { get; set; }
public string Name { get; set; }
public string Location { get; set; }
}
public static void Main()
{
var a1 = new A
{
Name = "XYZ",
Id = "123"
};
var a2 = new A
{
Name = "UVW",
Id = "567"
};
var aList = new List<A>()
{
a1,
a2
};
var b1 = new B
{
Location = "US",
Id = "123"
};
var b2 = new B
{
Location = "IN",
Id = "567"
};
var bList = new List<B>()
{
b1,
b2
};
var output = aList.Join(bList,
a => a.Id,
b => b.Id,
(a, b) => new AB
{
Id = a.Id,
Location = b.Location,
Name = a.Name
}).ToList();
foreach(var item in output)
{
Console.WriteLine(string.Format("Id : {0}, Name : {1}, Location:{1}", item.Id, item.Name, item.Location));
}
}
}