using System;
using System.Collections.Generic;
using System.Linq;
public class Program
{
public static void Main(string[] args)
{
List<Person> persons = new List<Person>
{
new Person { Id = 1, Name = "John", CityId = 1 },
new Person { Id = 2, Name = "Jane", CityId = 2 },
new Person { Id = 3, Name = "Bob", CityId = 1 },
new Person { Id = 4, Name = "Alice", CityId = 3 }
};
List<City> cities = new List<City>
{
new City { Id = 1, Name = "New York" },
new City { Id = 2, Name = "Los Angeles" },
new City { Id = 3, Name = "Chicago" }
};
var query = from person in persons
join city in cities on person.CityId equals city.Id
select new { person.Name, city.Name };
foreach (var result in query)
{
Console.WriteLine($"Person: {result.Name}, City: {result.Name}");
}
}
}
public class Person
{
public int Id { get; set; }
public string Name { get; set; }
public int CityId { get; set; }
}
public class City
{
public int Id { get; set; }
public string Name { get; set; }
}