James Archer James Archer - 1 year ago 148
C# Question

Saving a double array to a text file c#

I have an array of floating point numbers which has an unknown length as the the array is dynamic (it grows as new data is added to it). I need to find a way to store the data into a text file.

I would like the text file to be formatted in such a way that there is one floating point number per line.

I've been searching the web but could not find a solution, I'm new to c# so I would be very grateful if someone could point me in the right direction to solving the problem.

Answer Source

You can do it in a single line in .NET 4.0, like this:

    @"c:\data\myfile.txt" // <<== Put the file name here
,   myDoubles.Select(d => d.ToString()).ToArray()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download