0
Dictionary<DateTime, int> data1
Dictionary<DateTime, int> data2
if the dates in data1 is from **1/1/2000 - 1/1/2009** and the dates in data2 is from **1/1/2001 - 1/1/2007** then both Dictionaries<> should have the date ranging from **1/1/2001 - 1/1/2007**
는 주변의 다른 방법이 될 수
을 정렬되지 않습니다.bascailly 더 작은 범위 밖에있는 항목을 제거해야합니다 어떻게 C# 및 linq을 사용하여이 작업을 수행 할 수 있습니까?
public Dictionary<DateTime, int> ShrinkDictionary(
Dictionary<DateTime, int> dict, DateTime min, DateTime max) {
return dict.Where(kvp => InRange(kvp.Key, min, max))
.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
}
및 InRange
쉽게-일반화 방법은 다음과 같습니다
이 예에서 예. 하지만 둘 중 하나 일 수 있습니다. – newmem
'entry.Key '가 2001 년 1 월 1 일보다 크고'entry.Key'가 2007 년 1 월 1 일보다 작은'entry1'를'data1'에서 제거하고 싶다고 올바르게 이해하고 있습니까? 이것이 사실 인 것처럼 보이지만 그렇다면'data2'의 요점을 보지 못합니까? – jason
여기서 entry.Key가 2001 년 1 월 1 일보다 작고 entry.Key가 2007 년 1 월 1 일보다 큰 경우 data1에서 제거하십시오. data2는 동일하게 유지됩니다. – newmem