Created
May 16, 2024 05:39
-
-
Save mrange/bd4cac25d4ebdb7296906c093450d527 to your computer and use it in GitHub Desktop.
collection literals C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Gives an array of 3 elements | |
IEnumerable<ulong> x0 = Enumerable.Concat<ulong>([1], Unbounded()); | |
ulong[] y0 = x0.Take(3).ToArray(); | |
// Crashes with out of memory after some time | |
IEnumerable<ulong> x1 = [1, ..Unbounded()]; | |
ulong[] y1 = x0.Take(3).ToArray(); | |
IEnumerable<ulong> Unbounded() | |
{ | |
ulong i = 0; | |
while(true) | |
{ | |
++i; | |
Console.WriteLine($"Generated: {i}"); | |
yield return i; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment