1:先看效果:redis
2:部分代碼截圖ide
3:所有代碼spa
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 namespace Redistest02 5 { 6 class Program 7 { 8 static void Main(string[] args) 9 { 10 //Console.WriteLine("Hello DoSubscriberAsync!"); 11 //MyRedisHelper.DoSubscriberAsync("myredis").Wait(30); 12 //Console.ReadLine(); 13 14 //==================準備模擬兩張表的數據 15 var list01 = new List<Student>();//3條數據 16 Enumerable.Range(1, 3).ToList().ForEach(c => 17 { 18 list01.Add(new Student { id = 11 + c, Name = "qq" + c }); 19 }); 20 21 var list02 = new List<Student>();//兩條數據 22 list02.Add(new Student { id = 12, Name = "qq1" }); 23 list02.Add(new Student { id = 13, Name = "qq2" }); 24 25 Console.WriteLine("==========左鏈接==以左邊爲準============="); 26 //左鏈接 27 var newlistL = (from q in list01 28 join a in list02 29 on q.id equals a.id into qa 30 from c in qa.DefaultIfEmpty() 31 select new Student 32 { 33 id = c == null ? 0 : c.id, 34 Name = c == null ? "空的" : c.Name 35 }).ToList(); 36 newlistL.ForEach(c => Console.WriteLine($"id={c.id},name={c.Name}")); 37 38 //右鏈接 39 Console.WriteLine("==========右鏈接===以右邊爲準============"); 40 var newlistR = (from a in list02 41 join q in list01 42 on a.id equals q.id into qa 43 from c in qa.DefaultIfEmpty() 44 select new Student 45 { 46 id = c == null ? 0 : c.id, 47 Name = c == null ? "空的" : c.Name 48 }).ToList(); 49 newlistR.ForEach(c => Console.WriteLine($"id={c.id},name={c.Name}")); 50 51 //內鏈接 52 Console.WriteLine("==========內鏈接======兩邊共同的數據========="); 53 var newlistI = (from a in list02 54 join q in list01 55 on a.id equals q.id 56 select new Student 57 { 58 id = q == null ? 0 : q.id, 59 Name = q == null ? "空的" : q.Name 60 61 }).ToList(); 62 newlistI.ForEach(c => Console.WriteLine($"id={c.id},name={c.Name}")); 63 64 65 Enumerable.Range(1, 10).ToList().ForEach(c => 66 { 67 Console.WriteLine(c); 68 }); 69 var listdata = Enumerable.Empty<Student>(); 70 Console.WriteLine($"listdata的集合對象數據是:{listdata.Count()}個,null就會報錯的!"); 71 } 72 } 73 74 public class Student 75 { 76 public int id { get; set; } 77 public string Name { get; set; } 78 // public DateTime Birthday { get; set; } 79 80 //public IEnumerable<Student> GetSpectionMenthod 81 //{ 82 // get 83 // { 84 // // yield return Enumerable.Empty<Student>().FirstOrDefault(); 85 // yield return new Student { }; 86 // } 87 } 88 89 }
怎麼樣,看了以後仍是很簡單的對吧,嘻嘻!3d