Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _1._11._14
- {
- class Program
- {
- internal class Record
- {
- public int Id { get; set; }
- public string Name { get; set; }
- public int ParentID { get; set; }
- public Record(int a, string b, int? c)
- {
- Id = a;
- Name = b;
- if (c != null) ParentID = (int) c;
- }
- }
- private static void Main(string[] args)
- {
- var r11 = new Record(1, "Marc", null);
- var r12 = new Record(2, "Ivan", 1);
- var r13 = new Record(3, "Vasya", 2);
- var l = new List<Record> {r11, r12,r13};
- /*var l2 =
- from r in l // query expression
- where r.ParentID == 1
- select new{Num = r.Id, FIO=r.Name};*/
- var l2 =
- l.Where(r => r.ParentID == 1) //LINQ
- .Select(r3 => new {Num = r3.Id, FIO = r3.Name});
- Console.WriteLine(l2.First());
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement