拆分数组列表并返回长度不超过数组列表长度的字符串

本文关键字:列表 数组 字符串 不超过 返回 拆分 | 更新日期: 2023-09-27 18:11:57

autoComplete1.ServiceMethod = objdpt.LoadDpt(prefix); 

aspx.cs文件代码..调用loaddpt函数

public string LoadDpt(string prefixtext)
{
    //Functionality : AutoComplete The DepartmentName
    ArrayList  arlSample = new ArrayList();
    arlSample = objDataAccess.GetSingleColumn("QRY_DeptName", prefixtext);
    return arlSample;
    //string[] strArray = arlSample.ToArray(typeof(string)) as string[];   
}
上面的

是BLL文件代码。调用getsinglecolum函数

public ArrayList GetSingleColumn(string strQuery, params object[] objValueList)
{ 
    ArrayList arlData = new ArrayList();
    try
    {
        string strQry;
        strQry = ReadXmlvalue(strQuery, objValueList);
        cmdHrm = new OleDbCommand();
        cmdHrm.Connection = conHrmDb;
        if (conHrmDb.State == ConnectionState.Closed)
            conHrmDb.Open();
        cmdHrm.CommandText = strQry;
        drdHrm = cmdHrm.ExecuteReader();
        while (drdHrm.Read())
        {
            arlData.Add(drdHrm.ToString());
        }
        return arlData;
    }
    catch (Exception ex)
    {
        throw ex;
    }
    finally
    {
        if (conHrmDb.State == ConnectionState.Open)
            conHrmDb.Close();
    }
}
上面的

是dal文件代码。我想返回字符串到aspx.cs文件..help plz

拆分数组列表并返回长度不超过数组列表长度的字符串

如果你想将数组列表转换为字符串数组,你可以使用:

 IEnumerable<string> strings = arlSample.Cast<string>();
 string[] result = strings.ToArray();

如果你想连接所有的元素,这样你就可以返回一个字符串,你应该使用:

 string resultString = String.Concat(strings);