更新时间:2023-10-31 16:46:22
尝试如下操作:
DataTable table = new DataTable();
table.Columns.Add("name", typeof(string));
table.Columns.Add("value", typeof(string));
string name = "A,B,C,D";
string value = "100,200,300,400";
string[] names = name.Split(',');
string[] values = value.Split(',');
for(int i=0; i<names.Length; i++)
table.Rows.Add(new object[]{ names[i], values[i] });
但是您应该实现一些验证代码以使其更加实用合适的.
But you should implement some validation code to make it more appropriate.