JohnyWS

yield break example

Mar 31st, 2016
364
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // yield break example for Stack Overflow answer: http://stackoverflow.com/questions/3229698/how-can-i-return-an-empty-ienumerable/3229734#3229734
  2.  
  3. public IEnumerable<Friend> FindFriends()
  4. {
  5.   if(!userExists) yield break;
  6.  
  7.   foreach(var descendant in doc.Descendants("user").Select(user => new Friend
  8.     {
  9.         ID = user.Element("id").Value,
  10.         Name = user.Element("name").Value,
  11.         URL = user.Element("url").Value,
  12.         Photo = user.Element("photo").Value
  13.     }))
  14.   {
  15.     yield return descendant;
  16.   }
  17. }
RAW Paste Data