[英]Can't I use IEnumerable() on .ascx?
This is my code : 这是我的代码:
protected IEnumerable<MyObject> CategoriesHotelsFiltrati;
CategoriesHotelsFiltrati.Union(CategoriesHotels.Where(o => o.Comune != null && CategoriesLocalitaSelezionate.Contains(o.Comune.UniqueID)));
now, on .asxc, if I try to do : 现在,在.asxc上,如果我尝试这样做:
<%
if (m_oHotelsFiltrati == null || m_oHotelsFiltrati.Count()==0)
{
Response.Write("hello");
}
%>
seems that it doesnt find .Count()
method. 似乎它没有找到.Count()
方法。 It says somethings about "using" or "assembly". 它说有关“使用”或“组装”的事情。 Strange, with IList<>
this works perfectly...why? 奇怪,与IList<>
这完美地工作......为什么?
.Count()
is an extension method, it's not actually a method of IEnumerable
. .Count()
是一个扩展方法,它实际上不是IEnumerable
的方法。 You need to have a using
for System.Linq
for the compiler to find the method. 您需要using
System.Linq
来使编译器找到该方法。 (As per comment by Anthony Pegram, you would use the import
command for a markup file.) (根据Anthony Pegram的评论,您可以使用import
命令获取标记文件。)
It works fine with an IList because list actually has a property Count
; 它适用于IList,因为列表实际上有一个属性Count
; it doesn't rely on the extension method. 它不依赖于扩展方法。
With IList<>
you're probably calling the Count
property (without parentheses). 使用IList<>
您可能正在调用Count
属性(没有括号)。 You can call Count()
as a static method: 您可以将Count()
作为静态方法调用:
<%
if (m_oHotelsFiltrati == null || Enumerable.Count(m_oHotelsFiltrati)==0)
{
Response.Write("hello");
}
%>
I'm not sure how to get extension method resolution in the .ascx file. 我不知道如何在.ascx文件中获得扩展方法解析。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.