如果我有以下情况:
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);