How to write whole list? from System.Collections.Generic.List`1[System.String]?

I have created a list, now I want to display this list in one go? That is to say without using For each loop.

Thanks

1 Like

Hi @MGDEL,

Please try the following code below:
String.Join(Environment.NewLine, list.Select(Function(a) String.Join("", a)))

You don’t need the .Select, since List<T> already implements IEnumerable (if it wouldn’t, the Select call would actually be invalid since it’s from that interface :wink: ).
String.Join(Environment.NewLine, yourList)
will work just fine (same goes for arrays).

9 Likes

I am extracting a table and then ill filter using if condition and then ill will add that to collection. Now i want to go through all the values of collection but its not working as expected. Can any1 help.me out

Where are you stuck? @Darshhan

Im suprised they never ticked this as a solution. anyways thanks a lot @andrzej.kniola

1 Like

string.Join(Environment.NewLine, list1.ToArray()) , it will work.