Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# IEnumerable作为输出参数_C#_Asp.net_Linq_Entity Framework 4 - Fatal编程技术网

C# IEnumerable作为输出参数

C# IEnumerable作为输出参数,c#,asp.net,linq,entity-framework-4,C#,Asp.net,Linq,Entity Framework 4,我正在尝试写一个方法,从表中给出前10条记录和记录总数。无法确定如何访问输出参数。 它给出了一个错误-使用泛型类型IEnumerable需要1个类型参数。 请建议是否有更好的方法 达尔: public void GetData(out IEnumerable iList,out int rowCount) { iList=DBContext.tblcontries.Where(c=>c.Id>0).Take(10); rowCount=DBContext.tblcontries.Wher

我正在尝试写一个方法,从表中给出前10条记录和记录总数。无法确定如何访问输出参数。 它给出了一个错误-使用泛型类型IEnumerable需要1个类型参数。 请建议是否有更好的方法

达尔:

public void GetData(out IEnumerable iList,out int rowCount)
{    
iList=DBContext.tblcontries.Where(c=>c.Id>0).Take(10);
rowCount=DBContext.tblcontries.Where(c=>c.Id>0.Count();
}
BLL:

public void GetData(out IEnumerable iList,out int rowCount)
{    
GetData(out iList,out rowCount);
}
代码隐藏:

objBLL.(out IEnumerable<tblCountry> iList, out int rowCount);//Error here
objBLL.(out IEnumerable iList,out int rowCount)//这里出错

在代码隐藏中,您应该首先声明这两个变量,然后将它们作为
参数传递给GetData方法:

IEnumerable<tblCountry> iList;
int rowCount;
objBLL.GetData(out iList, out rowCount);
然后这样称呼它:

MyModel model = objBLL.GetData();
// here you could use model.Countries and model.RowCount

非常感谢你,达林。
IEnumerable<tblCountry> iList;
int rowCount;
objBLL.GetData(out iList, out rowCount);
public class MyModel
{
    public IEnumerable<tblCountry> Countries { get; set; }
    public int RowCount { get; set; }
}
public MyModel GetData()
{
    MyModel model = new MyModel();
    model.Countries = DBContext.tblCountries.Where(c=>c.Id > 0).Take(10);
    model.RowCount = DBContext.tblCountries.Where(c=>c.Id > 0).Count();
    return model;
}
MyModel model = objBLL.GetData();
// here you could use model.Countries and model.RowCount