How to tell whether an IEnumerable<T> has already been materialized in C#

There is no HasBeenEnumerated flag on IEnumerable . Here is what TryGetNonEnumeratedCount actually checks, why Enumerable.Range passes an ICollection test, and the guard that avoids a wasted ToList().