using System.Collections.Generic;
using System.Diagnostics;
public static void Main()
var stopwatch = Stopwatch.StartNew();
var ienumerable = Iterator();
Console.WriteLine($"Direct Assignment From Iterator: {stopwatch.ElapsedMilliseconds} ms");
var toList = Iterator().ToList();
Console.WriteLine($"Iterator ToList: {stopwatch.ElapsedMilliseconds} ms");
var any = Iterator().Any();
Console.WriteLine($"Iterator Any: {stopwatch.ElapsedMilliseconds} ms");
var countLinq = Iterator().Count();
Console.WriteLine($"Iterator Count LINQ: {stopwatch.ElapsedMilliseconds} ms");
var ienumerableToList = Iterator().ToList();
Console.WriteLine($"IEnumerable ToList: {stopwatch.ElapsedMilliseconds} ms");
var ienumerableAny = Iterator().Any();
Console.WriteLine($"IEnumerable Any: {stopwatch.ElapsedMilliseconds} ms");
var ienumerableCountLinq = Iterator().Count();
Console.WriteLine($"IEnumerable Count LINQ: {stopwatch.ElapsedMilliseconds} ms");
var listToList = toList.ToList();
Console.WriteLine($"List ToList: {stopwatch.ElapsedMilliseconds} ms");
var listAnyLinq = toList.Any();
Console.WriteLine($"List Any LINQ: {stopwatch.ElapsedMilliseconds} ms");
var listCountLinq = toList.Count();
Console.WriteLine($"List Count LINQ: {stopwatch.ElapsedMilliseconds} ms");
var countProperty = toList.Count;
Console.WriteLine($"List Count Property: {stopwatch.ElapsedMilliseconds} ms");
private static IEnumerable<int> Iterator()
for (int i = 0; i < 5; i++)
private static List<int> FunctionWithListReturnType()
var list = new List<int>();
foreach (var item in Iterator())