'SQL | C# - Reader rows

I have a small problem with MySqlDataReader. I have data in MySql and I have column "name" and X rows under. Reader reads sucessfully all of this but output is in one string and looks like "FirtSecondThird" but i need all of this words in list word by word. The code is:

            while (reader.Read())
            {
                vystup.Add(reader[0].ToString());
            }
            connection.Close();
            string out1 = "";
            foreach (string outage in vystup)
            {
                out1 += outage + "\n";
            }
            return out1;

Does anyone know what to do with it? Thanks.



Solution 1:[1]

You can use String.Join

if vystup is a List<string> which contains the following items "first", "second","third"

then outputting string.join(Enviorment.NewLine, vystup) will yield

"first"

"second"

"third"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 styx