I have a file with int values in each line (although it’s possible that some values are not ints like some comments). But the structure of the file is:
1
2
3
4
5
6
7
#some comment
9
10
etc...
What’s the fastest way to convert it to IEnumerable. I could read line by line and use List and call Add method, but I guess it’s not the best in terms of performance.
Thanks
You could create your
IEnumerableon-the-fly while reading the file:This way, you can do whatever you want to do with your integers while reading the file, using a
foreachloop.If you just want to create a list, simply use the
ToListextension:but there probably won’t be any measurable performance difference if you “manually” create a list as you described in your question.