1
foreach (set.row officeJoin in officeJoinMeta)
{
    foreach (set.somethingRow confRow in myData.something.Rows)
    {
        string dep = confRow["columnName"].ToString();
        depts.Add(dep);
    }
}

我让这个 for 循环遍历一列,将列中的每个值添加到 dep,然后将所有这些存储在我在此方法顶部定义的 List < String > depts 中。

dep 中的某些值是单个字符串,例如“R”,但有些值需要在逗号“R,GL,BD”之后分隔。

我理解使用 .Split(","),但是如何拆分字符串——如何获取数组中的每个值,用逗号拆分它们,然后将它们存储在另一个数组中?

4

3 回答 3

2

根据您解释的内容编写:

        foreach (set.row officeJoin in officeJoinMeta)
        {
            foreach (set.somethingRow confRow in myData.something.Rows)
            {
                string dep = confRow["columnName"].ToString();
                depts.AddRange(dep.Split(','));
            }
        }
于 2012-09-04T16:40:47.620 回答
0

声明为

List<string[]> depts =  new List<string[]>()

并添加为

depts.Add(dep.Split(','));
于 2012-09-04T16:43:05.787 回答
0
List<string> depts=new List<dept>();

    var values=dept].Split(',');

    for(int index=0;index<values.length;index++)
    {
    depts.Add(values[index].ToString());    

    }
于 2012-09-04T17:31:34.137 回答