-3
 static void Main(string[] args)
    {
        string[] myStringArray = {
            "Sum Ting Wong", "Wi Tu Low", "Ho Lee Fuk", "Bang Ding Ow" };
        string path = @"c:\Users\TEMP\test.txt";
        File.WriteAllLines(path, myStringArray);
        string[] read = File.ReadAllLines(path);
        Console.WriteLine(read);
        Console.ReadKey();
    }

My code currently prints to the file itself perfectly, however when I run the code, nothing is being read back to the console. I have done: File.ReadAllLines(path); and that should be reading it back to the console, but I get an output of:

System.String[]
Any suggestions?
Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
KlappDaddy
  • 27
  • 1
  • 10
  • it doesn't print anything to the console? you just throw away the result of the read – Keith Nicholas Sep 22 '17 at 02:27
  • 1
    @KeithNicholas Should I do a Console.WriteLine() ? Setting the File.ReadAllLines(path); to a variable? – KlappDaddy Sep 22 '17 at 02:29
  • @KlappDaddy exactly. – Blorgbeard Sep 22 '17 at 02:35
  • @Blorgbeard check my edit – KlappDaddy Sep 22 '17 at 02:43
  • See [this](https://stackoverflow.com/a/16265268/529282) – Martheen Sep 22 '17 at 02:47
  • @Martheen Thank you!! Got the answer, the one that worked best for my code was below the main answer, I also posted it below. – KlappDaddy Sep 22 '17 at 02:54
  • Odd, if you mean you want one liner to print in multiple arrays, the yourArray.ToList().ForEach(Console.WriteLine); should also works, assuming you aren't using pre-C# 3.0 (VS 2008 already support it) – Martheen Sep 22 '17 at 02:58
  • Yes that works as well, what is the difference between the two? Sorry I'm not too familiar on the difference. – KlappDaddy Sep 22 '17 at 03:01
  • 2
    This question isn't really about file IO at all. If you take *all* the "saving to a file and reading it" out, you're left with `string[] myStringArray = ...; Console.WriteLine(myStringArray);` which will still just print `System.String[]`. The question is really just "how do I print an array of strings to the console." – Jon Skeet Sep 22 '17 at 03:22
  • 1
    KlappDaddy, please *do not* post duplicate answers - if you found answer to your (or anyone else) question somewhere else on SO mark it as duplicate. Also make sure to read [MCVE] guidance carefully as @JonSkeet pointed out the post has absolutely nothing to do with file I/O which you could have figured yourself while creating really minimal example (your one actually reasonable enough as it contain all data necessary inline, but spending some more time to make it minimal could have pointed to answers directly) – Alexei Levenkov Sep 22 '17 at 03:45
  • @AlexeiLevenkov Someone pointed the answer to me above ^ I tried looking for a good amount of time before and haven't been online in a while, I will mark it as a duplicate now that I am aware. – KlappDaddy Sep 22 '17 at 04:05

1 Answers1

0
//Console.WriteLine(string.Join("\n", read));
read.ToList().ForEach(Console.WriteLine);

Either line of code supports the output I was looking for.

KlappDaddy
  • 27
  • 1
  • 10