C# Riddle #5

time to read 1 min | 184 words

Following Alex's post about traps in interviews, I thought about posting bits of code that I won't use in interviews. Mostly because I don't think that it is fair to the interviewee. I can think about crazy usages to langauge features, and not in a good way.

Consider the following peice of code (which is valid C# 2.0):

public IEnumerable<Predicate<Customer>> ValidationPipeline()
{
 yield return delegate(Customer c)
 {
  return c.Name != "";
 };
 
 yield return delegate(Customer c)
 {
  return EmailService.IsValid(c.Email);
 };
}

How would you use this method, and what is wrong with it?