Reputation: 47945
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 :
<%
if (m_oHotelsFiltrati == null || m_oHotelsFiltrati.Count()==0)
{
Response.Write("hello");
}
%>
seems that it doesnt find .Count()
method. It says somethings about "using" or "assembly". Strange, with IList<>
this works perfectly...why?
Upvotes: 2
Views: 499
Reputation: 12226
You need to add the following line to your *.ascx
file:
<%@ Import namespace="System.Linq" %>
See this link for more details.
Upvotes: 5
Reputation: 203817
.Count()
is an extension method, it's not actually a method of IEnumerable
. You need to have a using
for System.Linq
for the compiler to find the method. (As per comment by Anthony Pegram, you would use the import
command for a markup file.)
It works fine with an IList because list actually has a property Count
; it doesn't rely on the extension method.
Upvotes: 2
Reputation: 43046
With IList<>
you're probably calling the Count
property (without parentheses). You can call Count()
as a static method:
<%
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.
Upvotes: 2