Skip to content

Instantly share code, notes, and snippets.

@ssippe
Created September 14, 2020 23:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssippe/dcf36ce77bf3bfdd18733ae0dcf92e2c to your computer and use it in GitHub Desktop.
Save ssippe/dcf36ce77bf3bfdd18733ae0dcf92e2c to your computer and use it in GitHub Desktop.
List generation with optional members and immutable variables
static IReadOnlyList<int> GenerateList(int option)
{
IEnumerable<int> F()
{
if (option > 0)
yield return 1;
if (option > 1)
yield return 2;
if (option > 3)
yield return 3;
}
return F().ToList();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment