Given the following code and the suggestions given in this question, I\'ve decided to modify this original method and ask if there are any values in the IEnumarable return i
That's of course only a matter of personal preference, but I'd write this function using yield return:
public IEnumerable FindFriends()
{
//Many thanks to Rex-M for his help with this one.
//http://stackoverflow.com/users/67/rex-m
if (userExists)
{
foreach(var user in doc.Descendants("user"))
{
yield return new Friend
{
ID = user.Element("id").Value,
Name = user.Element("name").Value,
URL = user.Element("url").Value,
Photo = user.Element("photo").Value
}
}
}
}