Skip to content

Instantly share code, notes, and snippets.

@Grinderofl
Created May 9, 2017 09:38
Show Gist options
  • Save Grinderofl/43c5c1cb771dac0d60597d9da3a5f8ff to your computer and use it in GitHub Desktop.
Save Grinderofl/43c5c1cb771dac0d60597d9da3a5f8ff to your computer and use it in GitHub Desktop.
public IEnumerable<YourType> GetYourTypes()
{
yield return GetElement();
foreach(var el in GetOtherElements())
yield return el;
}
var types = GetYourTypes();
if(!types.Any()) // possible multiple enumerations of enumerable
// Do something
foreach(var type in types) // possible multiple enumerations of enumerable
// Do something
vs
var types = GetYourTypes.ToList();
if(!types.Any())
// Do something
foreach(var type in types)
// Do something
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment