分段字符串,用逗号,但是最后一个就没有逗号
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace ADOperation{ public partial class Form2 : Form { public Form2() { InitializeComponent(); MessageBox.Show("welcome " + SpiltString() + " come here!"); } public List<Student> StudentList() { List<Student> listStudent = new List<Student>(); Student s1 = new Student(); s1.ID = 1; s1.Name = "apple"; listStudent.Add(s1); Student s2 = new Student(); s2.ID = 2; s2.Name = "wendy"; listStudent.Add(s2); Student s3 = new Student(); s3.ID = 3; s3.Name = "XiaoMin"; listStudent.Add(s3); Student s4 = new Student(); s4.ID = 4; s4.Name = "Easy"; listStudent.Add(s4); return listStudent; } private string SpiltString() { string students = string.Empty; string student = string.Empty; foreach (Student s in StudentList()) student += s.Name + ","; int jobNoIndex = (student + "last").IndexOf(",last"); students = (student + "last").Substring(0, jobNoIndex); return students; } } public class Student { public decimal ID { get; set; } public string Name { get; set; } }}