Guest User

Untitled

a guest
Jan 10th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. LINQ
  2.  
  3.  
  4.  
  5. int[] numbers = new int[7] { 0, 1, 2, 3, 4, 5, 6 };
  6.  
  7. var numQuery =
  8. from num in numbers
  9. where (num % 2) == 0
  10. select num;
  11.  
  12. foreach (int num in numQuery)
  13. {
  14. Console.Write("{0,1} ", num);
  15. }
  16.  
  17.  
  18. ---------------
  19.  
  20.  
  21. List<Student> studentList;
  22. studentList =
  23. new List<Student> {
  24. new Student { ID = 1, Name = "Tornike", Surname = "Kipiani", Country = "Georgia", Scholarship = 1 },
  25. new Student { ID = 2, Name = "Giorgi", Surname = "Tchkadua", Country = "USA", Scholarship = 500 },
  26. new Student { ID = 3, Name = "Nika", Surname = "Begoidze", Country = "Georgia", Scholarship = 0 }
  27. };
  28.  
  29. var studentsQuery = from st in studentList
  30. where st.Country == "Georgia"
  31. select new { st.Country, st.ID, st.Name, st.Surname };
  32.  
  33. foreach (var stud in studentsQuery)
  34. label1.Text = label1.Text + " , " + stud.ToString();
  35. ----------------
  36.  
  37. DataContext db = new DataContext(@"c:\tornike.mdf");
  38.  
  39. =============================================================
  40.  
  41. 1) 5
  42. 2) 2
  43. 3) 4
  44. 4) 5
  45. 5) 3
  46. 6) 4
  47. 7) 1
  48. 8) 1
  49. 9) 2
  50. 10) 3
  51. 11) 3
  52. 12) 4
  53. 13) 4
  54. 14) 1
  55. 15) 2,3
Advertisement
Add Comment
Please, Sign In to add comment