Would there be any performance improvement to add a check of the count of a collection before enumerating the contents with foreach?
if (users.Count != 0) {
foreach (var user in users) {
// do what snowmen do in summer
}
}
vs.
foreach (var user in users) {
// do what snowmen do in summer
}
My function is taking a little too long, so I'd like to know if this will improve performance even a little to get my function execution time down to where I need it.
Edit (context in which this loop executes):
for (DateTime day = dayStart; day < dayEnd; day = day.addMinutes(30)) {
// Other actions
if (users.Count != 0) {
foreach (var user in users) {
// do what snowmen do in summer
}
}
}