[LINQ] 여러 인풋을 하나의 시퀀스로 Join 하기
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
Joining Multiple Inputs into One Output Sequence
You can use a LINQ query to create an output sequence that contains elements from more than one input sequence. The following example shows how to combine two in-memory data structures, but the same principles can be applied to combine data from XML or SQL or DataSet sources. Assume the following two class types:
class Student { public string First { get; set; } public string Last {get; set;} public int ID { get; set; } public string Street { get; set; } public string City { get; set; } public List<int> Scores; } class Teacher { public string First { get; set; } public string Last { get; set; } public int ID { get; set; } public string City { get; set; } }
The following example shows the query:
class DataTransformations { static void Main() { // Create the first data source. List<Student> students = new List<Student>() { new Student {First="Svetlana", Last="Omelchenko", ID=111, Street="123 Main Street", City="Seattle", Scores= new List<int> {97, 92, 81, 60}}, new Student {First="Claire", Last="O’Donnell", ID=112, Street="124 Main Street", City="Redmond", Scores= new List<int> {75, 84, 91, 39}}, new Student {First="Sven", Last="Mortensen", ID=113, Street="125 Main Street", City="Lake City", Scores= new List<int> {88, 94, 65, 91}}, }; // Create the second data source. List<Teacher> teachers = new List<Teacher>() { new Teacher {First="Ann", Last="Beebe", ID=945, City = "Seattle"}, new Teacher {First="Alex", Last="Robinson", ID=956, City = "Redmond"}, new Teacher {First="Michiyo", Last="Sato", ID=972, City = "Tacoma"} }; // Create the query. var peopleInSeattle = (from student in students where student.City == "Seattle" select student.Last) .Concat(from teacher in teachers where teacher.City == "Seattle" select teacher.Last); Console.WriteLine("The following students and teachers live in Seattle:"); // Execute the query. foreach (var person in peopleInSeattle) { Console.WriteLine(person); } Console.WriteLine("Press any key to exit."); Console.ReadKey(); } } /* Output: The following students and teachers live in Seattle: Omelchenko Beebe */
'Language > C#' 카테고리의 다른 글
[LINQ] 메모리상의 객체를 XML 로 변환하기 (671) | 2015.04.28 |
---|---|
[LINQ] subset 부분 집합 구하기 (6) | 2015.04.28 |
C# 자료 정리 - SerialPort. Event, Thread Synchronization, Debug Trace, TextBox Carrot Control, TimSpan, Method Invoker, Invoke (6) | 2015.04.28 |
C# Thread 를 이용한 코드에서 DEBUG 하기. winForm 의 화면제어시 오류피하기 [출처] C# Thread 를 이용한 코드에서 DEBUG 하기. winForm 의 화면제어시 오류피하기|작성자 바람 (6) | 2015.04.28 |
New Features in C# 6 (6) | 2015.04.28 |