using System.Xml.Linq;
public class Example
{
public static void Main()
{
Console.Write("IEnumerable<T> 의 join 키워드 사용 \n");
List<Customer> customers = new List<Customer>();
customers.Add(new Customer() { City = "Seoul", FirstName = "Code", LastName = "Killer" });
customers.Add(new Customer() { City = "Seoul", FirstName = "Code1", LastName = "Killer1" });
customers.Add(new Customer() { City = "Seoul", FirstName = "Code2", LastName = "Killer2" });
customers.Add(new Customer() { City = "Seoul", FirstName = "Code3", LastName = "Killer3" });
List<Customer2> customers2 = new List<Customer2>();
customers2.Add(new Customer2() { City = "Seoul", FirstName = "Dragon", LastName = "Ball" });
customers2.Add(new Customer2() { City = "Seoul", FirstName = "Dragon1", LastName = "Ball1" });
var innerJoinQuery =
from cust in customers
join dist in customers2 on cust.City equals dist.City
select new { CustomerName = cust.FirstName, DistributorName = dist.FirstName };
foreach (var customerGroup in innerJoinQuery)
{
Console.WriteLine("CustomerName : {0}", customerGroup.CustomerName);
Console.WriteLine("DistributorName : {0}", customerGroup.DistributorName);
}
}
}
public class Customer
{
public string City { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
public class Customer2
{
public string City { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}