■ DynamicQueryable 클래스의 Where<T> 확장 메소드를 사용하는 방법을 보여준다.
▶ Student.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
namespace TestProject { /// <summary> /// 학생 /// </summary> public class Student { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 성명 - Name /// <summary> /// 성명 /// </summary> public string Name { get; set; } #endregion #region 나이 - Age /// <summary> /// 나이 /// </summary> public int Age { get; set; } #endregion } } |
▶ Program.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
using System; using System.Collections.Generic; using System.Data; using System.Linq.Dynamic; namespace TestProject { /// <summary> /// 프로그램 /// </summary> class Program { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Private #region 프로그램 시작하기 - Main() /// <summary> /// 프로그램 시작하기 /// </summary> private static void Main() { List<Student> list = new List<Student>(); list.Add(new Student { Name = "홍길동", Age = 20 }); list.Add(new Student { Name = "김영희", Age = 30 }); list.Add(new Student { Name = "이동수", Age = 20 }); list.Add(new Student { Name = "강동원", Age = 50 }); foreach(Student student in list.Where("Age > 20")) { Console.WriteLine(student.Name); } } #endregion } } |