Advertisement
Guest User

Untitled

a guest
Nov 1st, 2014
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _1._11._14
  8. {
  9. class Program
  10. {
  11. internal class Record
  12. {
  13. public int Id { get; set; }
  14.  
  15. public string Name { get; set; }
  16.  
  17. public int ParentID { get; set; }
  18.  
  19. public Record(int a, string b, int? c)
  20. {
  21. Id = a;
  22. Name = b;
  23. if (c != null) ParentID = (int) c;
  24. }
  25. }
  26.  
  27. private static void Main(string[] args)
  28. {
  29. var r11 = new Record(1, "Marc", null);
  30. var r12 = new Record(2, "Ivan", 1);
  31. var r13 = new Record(3, "Vasya", 2);
  32.  
  33. var l = new List<Record> {r11, r12,r13};
  34.  
  35. /*var l2 =
  36. from r in l // query expression
  37. where r.ParentID == 1
  38. select new{Num = r.Id, FIO=r.Name};*/
  39. var l2 =
  40. l.Where(r => r.ParentID == 1) //LINQ
  41. .Select(r3 => new {Num = r3.Id, FIO = r3.Name});
  42. Console.WriteLine(l2.First());
  43.  
  44.  
  45. Console.ReadLine();
  46. }
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement