나는 다음과 같은 경우 :클로저에서 고정 된 읽기 전용 값 유형이 해제 되었습니까?
static readonly TimeSpan ExpiredAfter = TimeSpan.FromMilliseconds(60000);
foreach (ModuleInfo info in moduleList.Where(i => DateTime.Now - i.LastPulseTime > ExpiredAfter).ToArray())
moduleList.Remove(info);
은 해제 얻을 ExpiredAfter 않거나 컴파일러는 직접 액세스 할 수 있습니다 알고 있나요? 이런 식으로 작성하는 것이 더 효율적이 될 것이다 :
static readonly TimeSpan ExpiredAfter = TimeSpan.FromMilliseconds(60000);
static bool HasExpired(ModuleInfo i) { return DateTime.Now - i.LastPulseTime > ExpiredAfter; }
foreach (ModuleInfo info in moduleList.Where(HasExpired).ToArray())
moduleList.Remove(info);
저는 위임자 생성, 멋진 답변을 잊어 버렸습니다! – Tergiver
나는 이것이 컴파일러로 하여금 생각하게하는 또 다른 사례라고 생각한다.) – Tergiver
@Tergiver : 매우 사실. 그러나 영향을보기 위해 벤치마킹 할 가치가 있습니다. – Ani