Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Namespace Begvcsharp_23_15_setoperators {class Customer {public string ID {get; set;}
public string City {get; set;}
public string Country {get; set;}
public string Region {get; set;}
Public decimal Sales {get; set;}
Class Order {public string ID {get; set;}
Public decimal Amount {get; set;} Class Program {static void Main (string[] args) {list<order> orders = new List<order> {id= "P", amount=100}, New Order {id= "Q", amount=20 0}, New Order {id= ' R ', amount=300}, New Order {id= ' S ', amount=400}, N EW Order {id= ' T ', amount=500}, New Order {id= ' U ', amount=600}, New Order {ID= "V", amount=700}, New Order {id= "W", amount=800}, New Order {id= "X", amount=900},
New Order {id= "Y", amount=1000}, new, {id= "Z", amount=1100}}; List<customer> customers = new List<customer> {new Customer {id= "A", city= "New Yor" K ", country=" USA ", region=" North America ", sales=9999}, new Customer {id=" B ", city=" Mumbai ", country=" Ind " IA ", region=" Asia ", sales=8888}, new Customer {id=" C ", city=" Karachi ", country=" Pakistan ", region=" Asia ",
sales=7777}, new Customer {id= "D", city= "Delhi", country= "India", region= "Asia", sales=6666}, New Customer {id= "E", city= "so Paulo", country= "Brazil", region= "South America", sales=5555}, new Customer {id= "F", city= "Moscow", country= "Russia", region= "Europe", sales=4444}, new Customer {id= "G", city= "Seoul", country= "KoRea ", region=" Asia ", sales=3333}, new Customer {id=" H ", city=" Istanbul ", country=" Turkey ", region=" Asia "
, sales=2222}, new Customer {id= "I", city= "Shanghai", country= "in", region= "Asia", sales=1111}, New Customer {id= "J", city= "Lagos", country= "Nigeria", region= "Africa", sales=1000}, new Cus Tomer {id= "K", city= "Mexico City", country= "Mexico", region= "North America", sales=2000}, new Customer { Id= "L", city= "Jakarta", country= "Indonesia", region= "Asia", sales=3000}, new Customer {id= "M", city= "to Kyo ", country=" Japan ", region=" Asia ", sales=4000}, new Customer {id=" N ", city=" Los Angeles ", country=" US A ", region=" North America ", sales=5000}, new Customer {id=" O ", city=" Cairo ", country=" Egypt ", region=" Af
Rica ", sales=6000}, new Customer {id=" P ", city=" Tehran ", country=" Iran ", region=" Asia ", sales=7000}, New Customer {id= "Q", city= "London", country= "UK", region= "Europe", sales=8000}, new Customer {id= "R", city= "Beij" ing ", country=", region= "Asia", sales=9000}, new Customer {id= "S", city= "Bogotá", country= "Colombi" A ", region=" South America ", sales=1001}, new Customer {id=" T ", city=" Lima ", country=" Peru ", region=" Sout "
H America ", sales=2002}};
var customerids = from C in customers select C.id;
var orderids = from O in orders select O.id;
var customerswithorders = Customerids.intersect (orderids);
Console.WriteLine ("Customers with Orders:");
foreach (var item in customerswithorders) {Console.Write ("{0}", item);
} Console.WriteLine (); Console.WriteLine ("Orders with no C"Ustomers: ");
var ordersnocustomers = orderids.except (customerids);
foreach (var item in ordersnocustomers) {Console.Write ("{0}", item);
} Console.WriteLine ();
Console.WriteLine ("All Customer and Order IDs:");
var allcustomerorderids = orderids.union (customerids);
foreach (var item in allcustomerorderids) {Console.Write ("{0}", item);
} Console.WriteLine ();
Console.Write ("program finished, press Enter/return to continue:");
Console.ReadLine (); }
}
}
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/net/