© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
47 replies
Tony Wang

C# IEnumerable ToArray() Benchmark

I was benchmarking different kinds of IEnumerable Methods out of curiosity and found something very strange: Calling ToArray() on a temporary array is relatively slow.

I am aware, that array.ToArray() creates a copy of array, but I would have thought that the compiler was smart enough to ommit the copy if array is an temporary object. Am I missing something?
Screenshot_2024-04-19_162540.png
Screenshot_2024-04-19_162557.png
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

IEnumerable<Author>
C#CC# / help
3mo ago
❔ When should you benchmark using Benchmark.NET
C#CC# / help
4y ago
IEnumerable and loops
C#CC# / help
6mo ago