1.首先在该命名空间下创建一个实体,和在Main方法下List集合,为后续做准备:

C#如何从List集合中读取元素后在每个元素间插入一个逗号","?

 

第一种方法:

 

string str = string.Empty;
 for (int i = 0; i < stu.Count; i++)
{
     str += stu[i].Name+",";
}
str=str.TrimEnd(',');//去掉最后一个逗号

 

C#如何从List集合中读取元素后在每个元素间插入一个逗号","?

 

第二种方法:

 

string str = string.Empty;
for (int i = 0; i < stu.Count; i++)
{
  if (i == stu.Count - 1)
  {
      str += stu[i].Name;
    }
    else
    {
         str += stu[i].Name + ",";
     }
}
Console.WriteLine(str);

 

C#如何从List集合中读取元素后在每个元素间插入一个逗号","?

相关文章:

  • 2022-12-23
  • 2021-06-26
  • 2021-07-10
  • 2021-06-01
  • 2022-12-23
  • 2021-10-15
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-22
  • 2021-12-15
  • 2021-12-03
  • 2022-02-06
相关资源
相似解决方案