CKTIS / C#
Enumerable.ToList: practical reference
Enumerable.ToList: practical reference: Immediately enumerates and copies elements into a new mutable List<T>.
Version: .NET LINQ; verified on .NET 10.0.14
Syntax
source.ToList(/* overload-specific arguments */)Immediately enumerates and copies elements into a new mutable List.
Use it as a snapshot and when List methods or repeated enumeration without rereading the source are needed.
It is a shallow reference copy. A large or infinite source can exhaust memory or never complete.
An empty source yields an empty list; a null source causes ArgumentNullException.
The complete program actually uses Enumerable.ToList; its exact expected stdout is 4.
Examples
using System;
using System.Collections.Generic;
using System.Linq;
var list = Enumerable.Range(1, 3).ToList();
list.Add(4);
Console.WriteLine(list.Count);
Result
4
The complete program actually uses `Enumerable.ToList`; its exact expected stdout is `4`.