Printing a comma (,) after each item in an array

前端 未结 7 760
轮回少年
轮回少年 2020-12-20 17:28

Lets say I have an array (or list) of items

A[] = [a,b,c,d,e]

If I want to print them out so each item is separated by a comma (or any othe

7条回答
  •  囚心锁ツ
    2020-12-20 17:45

    using System;
    using System.Linq;
    
    public class Program
    {
        public static void Main()
        {
            string[] values = new string[]{"banana", "papaya", "melon"};
    
            var result = values.Aggregate((x,y) => x + ", " + y);
    
            Console.WriteLine(result);
        }
    }
    

提交回复
热议问题