Chaostante
Chaostante

Reputation: 37

Queue up arrays or write Queue to more dimensional array?

I've got arrays of floats with 4 floats each. I'd like to queue them up to later write the content of the queue to a file. I use this code:

In my "MasterScript.cs":

public static Queue <float> my_pointsQ = new Queue <float> ();

Fill queue with content:

for (int i = 0; i < points_count; ++i)
            {
                MasterScript.my_pointsQ.Enqueue(my_points[i]);

            }

write queue to file:

using(StreamWriter writer = new StreamWriter(file)){
    foreach (float point in MasterScript.my_pointsQ) 
    writer.WriteLine (point);
}

It works, but I got all the floats one per line. I'd like to have four floats per line as the original m_pointsare arrays of four floats each... Is there a possibility to queue up arrays of floats? (When I delete the <float> in the MasterScript and adress points by foreach (object point in MasterScript.my_pointsQ) I got single lines too.)

Or is there a way to copy my queue to a four-dimensional array?

Upvotes: 2

Views: 998

Answers (2)

Hack
Hack

Reputation: 144

You should be able to store the arrays in the queue

public static Queue <float[]> my_pointsQ = new Queue <float[]> ();

Then you should be able to write them like this

using(StreamWriter writer = new StreamWriter(file))
{
    foreach (float[] point in MasterScript.my_pointsQ) 
         writer.WriteLine (string.Join(",",point);
}

I used a "," as my separator but you can leave it blank, or change it to whatever you want.

Upvotes: 1

Jakub Rusilko
Jakub Rusilko

Reputation: 867

You can just queue up the arrays by changing the Queue type to

public static Queue <float[]> my_pointsQ = new Queue <float[]> ();

See this: fiddle

Upvotes: 1

Related Questions