■ 날짜 문자열을 갖는 속성 값 검색하기

----------------------------------------------------------------------------------------------------

using System;

using System.Linq;

 

var itemArray = new[]

{

    new { Name = "A", StartDate = "20151210", EndDate = "20151231"},

    new { Name = "B", StartDate = "20151201", EndDate = "20151231"},

    new { Name = "C", StartDate = "20151207", EndDate = "20151208"},

    new { Name = "D", StartDate = "20151217", EndDate = "20151231"},

    new { Name = "E", StartDate = "20151203", EndDate = "20151210"}

};

 

var baseDate = "20151210";

 

var result = itemArray.Where(item => item.StartDate.CompareTo(baseDate) <= 0 && item.EndDate.CompareTo(baseDate) >= 0);

 

foreach(var item in result)

{

    Console.WriteLine(item);

}

----------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG