When I save data in a text file there is a redundant line at the end, what is it(C#)?

StackOverflow https://stackoverflow.com/questions/22159825

  •  19-10-2022
  •  | 
  •  

Question

I faced an interesting point. I have a foreach loop for writing data in a List array. Interestingly, there is this message at the end of the text file :

System.Collections.Generic.List`1[System.Double]

What is it? Is it because of this line (writer.WriteLine(BoundaryLayerCheck0.ToString());) ?

string path = string.Concat(Environment.CurrentDirectory, @"\Output\+1+".txt");

        using (FileStream fs0 = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write))
        using (StreamWriter writer = new StreamWriter(fs0))
        {
            foreach (double x in BoundaryLayerCheck0)
            {
                writer.WriteLine(x);
            }
            writer.WriteLine(BoundaryLayerCheck0.ToString());
        }
Was it helpful?

Solution

You answered your own question.

BoundaryLayerCheck0.ToString() will return the fully qualified type of the object (unless you have overridden the ToString() method.

More info here http://msdn.microsoft.com/en-us/library/system.object.tostring%28v=vs.110%29.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top