【问题标题】:split the arraylist and return as string upto the length of arraylist拆分 arraylist 并作为字符串返回,直到 arraylist 的长度
【发布时间】:2011-12-13 03:24:19
【问题描述】:
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 file..help plz

【问题讨论】:

    标签: c# autocomplete arraylist n-tier-architecture


    【解决方案1】:

    如果要将 ArrayList 转换为字符串数组,可以使用:

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

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

     string resultString = String.Concat(strings);
    

    【讨论】:

    • 我不想连接..但是每个字符串必须单独返回
    • 然后返回结果字符串数组。这将分别返回每个字符串。您不能从一个函数返回多个结果,除非您使用带有 'yield' 的迭代器之类的东西。
    • 但是函数调用只需要字符串而不是字符串数组。这就是我面临的问题
    • 您不能为只需要一个字符串的函数返回多个字符串。你到底想做什么?请编辑您的帖子以提供更多信息。
    猜你喜欢
    • 2012-08-29
    • 1970-01-01
    • 2012-05-28
    • 2014-08-19
    • 1970-01-01
    • 1970-01-01
    • 2021-02-03
    • 2014-03-14
    • 1970-01-01
    相关资源
    最近更新 更多