从静态类方法或实例方法中检索列表?

时间:2019-10-02 14:27:41

标签: c#

我正在尝试从数据库中获取列表的健全性检查。

我可以使用静态方法基于传递的参数返回修改后的列表吗?

我还能在多大程度上使用静态方法返回列表?有人可以指出一些现实生活中的例子吗?代码一切正常,但是最近有了顿悟。

这里是一个例子:

/// <summary>
/// Returns list of All Projects based on array of enum StatusOfProject
/// </summary>
/// <param name="theStatus"></param>
/// <returns></returns>
public static IEnumerable<string> List(params Status[] theStatus)
{
    ThrowIf.Argument.IsNull(theStatus);
    var selectedStatus = new List<string>();
    foreach (Status nextStatus in theStatus)
    {
        string theQuery = "select JobNo from ProjectLog where StatusID = " + (int)nextStatus + "  order by JobNo desc";
        using (SqlDataAdapter theSqlAdapter = new SqlDataAdapter(theQuery, TheUtils.OurDBHelpers.GetOurConnectionString()))
        {
            DataSet theDataset = new DataSet();
            theSqlAdapter.Fill(theDataset, "Table");
            DataTable theDataTable = theDataset.Tables["Table"];
            selectedStatus.AddRange(theDataTable.AsEnumerable().Select(row => row["JobNo"].ToString()));
        }
    }

    return selectedStatus;
}

0 个答案:

没有答案