private int ExpireCollection(CookieCollection cc) {
int oldCount = cc.Count;
int idx = oldCount-1;
// minor optimization by caching Now
DateTime now = DateTime.Now;
lock (cc) {
//Cannot use enumerator as we are going to alter collection
while (idx >= 0) {
Cookie cookie = cc[idx];
if (cookie.Expires <= now && cookie.Expires != DateTime.MinValue) {
cc.RemoveAt(idx);
}
--idx;
}
}
return oldCount - cc.Count;
}