Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I would like to write my result set to a text file without using a For Each Loop. Is there a quicker more efficient way to stream Linq to Entities or Linq to Objects?
Posted
Comments
Hariharan Arunachalam 29-Apr-11 1:08am    
Could you elaborate on the way the object is to be stored into the text file? And your source collection.

1 solution

I am going to assume you need to store an IEnumerable(Of String) into a file separated by comma. This can be done fairly directly using the Aggregate extension.


VB
' We need to write the IEnumerable(Of String) SourceCollection into the text file "Numbers.txt"
        My.Computer.FileSystem.WriteAllText("numbers.txt", SourceCollection.Aggregate(Function(item, aggregator) String.Format("{1},{0}", aggregator, item)), False)
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900