Reputation: 217
I am trying to find the number of unique dates in my list.
IEnumerable<T>
public int CountUniqueDate()
{
return _items.DistinctBy(i => i.DateMeasured).Count();
}
I think, this function will tell me the count of the unique dates in the list.
Now, from the other file, I try to retrieve the value
Either I want the count or the condition which will tell whether it is one or not.
So I try this to check whether the count is 1 or not.
But, here i get compilation error.
If I do var ans
, then I get a full list.
List<T> li;
bool ans= li.Where(x => x.Measures.CountUniqueDate() == 1);
Can anyone please help me.
I wanna check, if the CountUniqueDate returns value 1 or not.
Upvotes: 2
Views: 165
Reputation: 4130
Change your method to be an extension method like this
public static class Extensions
{
public static int CountUniqueDate(this List<Measure> items) //<= measure is your T type
{
return items.DistinctBy(i => i.DateMeasured).Count();
}
}
then you can call it like this:
List<Measure> li = YourData;
bool ans= li.CountUniqueDate() == 1;
Upvotes: 0
Reputation: 505
If you wan't to check if the there is one with count = 1 or not you might use
bool ans= li.Any(x => x.Measures.CountUniqueDate() == 1);
Upvotes: 1
Reputation: 10693
The WHERE CLAUSE doesnt return a boolean but an IEnumerable(Of TSource)
Upvotes: 2