C# output array, how to separate each element with a comma

Found this problem while writing homework,
1. If you use a for loop

for (int j = array1.Length-1; j >-1; j--)
            {
    
    
                Console.Write(array1[j]+",");
            }

There is also a comma at the end of the output

2. Use the foreach statement

foreach(var item in array)
    Console.WriteLine(item);

Then the output results are all connected

3. Converted into string format

Console.WriteLine(string.Join(",", array1));

Then the output is satisfactory

The test is as followsInsert picture description here

Guess you like

Origin blog.csdn.net/NikoHsu/article/details/106046731