CSharp · Console
using System;
using System.Linq;
public class Program
{
public static void Main()
{
var people = new[]
{
new { Name = "Vernon", Gender = "Male", CountryCode = "GB" },
new { Name = "Carrie", Gender = "Female", CountryCode = "CA" },
new { Name = "Joanna", Gender = "Female", CountryCode = "US" },
new { Name = "Thomas", Gender = "Male", CountryCode = "ES" }
};
var countries = new[]
{
new {CountryName = "United Kingdom", Code = "GB"},
new {CountryName = "United States", Code = "US"},
new {CountryName = "Canada", Code = "CA"},
new {CountryName = "France", Code = "FR"},
new {CountryName = "Spain", Code = "ES"}
};
var results = people.Join(countries,
arg => arg.CountryCode, // the key to join from the people list
arg => arg.Code, // the key to join from the country list
(person, country) => new { person.Name, country.CountryName }); // the select of the join
foreach (var x in results)
{
Console.WriteLine("{0} {1}", x.Name, x.CountryName);
}
}
}