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