1. 程式人生 > >C# LINQ詳解(一)

C# LINQ詳解(一)

複製程式碼
 1 using System.Collections; 
 2 
 3 using System.Collections.Generic; 
 4 
 5 using System.Linq; 
 6 
 7  
 8 
 9 namespace Chapter_5 
10 
11 { 
12 
13     class Program 
14 
15     { 
16 
17         static void Main(string[] args) 
18 
19         { 
20 
21  
22 
23             IList<Person> persons = new
List<Person>(); 24 25 IList<int> numbers = new List<int>(); 26 27 IList<string> names = new List<string>(); 28 29 30 31 var defaultPersons = persons.DefaultIfEmpty(); 32 33 34 35 var defaultNumbers = numbers.DefaultIfEmpty().ToList();
36 37 38 39 var defaultNames = names.DefaultIfEmpty(); 40 41 } 42 43 } 44 45 46 47 class Person 48 49 { 50 51 public string Name 52 53 { 54 55 get; 56 57 set; 58 59 } 60 61 62 63 public
string Address 64 65 { 66 67 get; 68 69 set; 70 71 } 72 73 74 75 public int Age 76 77 { 78 79 get; 80 81 set; 82 83 } 84 85 } 86 87 }
複製程式碼