Padraic Cunningham Padraic Cunningham - 1 year ago 114
C# Question

printing all contents of array in C#

I am trying to print out the contents of an array after invoking some methods which alter it, in Java I use:


how do I do this in c#?

Answer Source

You may try this:

foreach(var item in yourArray)

Also you may want to try something like this:

yourArray.ToList().ForEach(i => Console.WriteLine(i.ToString()));

EDIT: Or as suggested in comments:


EDIT: to get output in one line [based on your comment]:

 Console.WriteLine("[{0}]", string.Join(", ", yourArray));
 //output style:  [8, 1, 8, 8, 4, 8, 6, 8, 8, 8]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download