C
C#•2y ago
Natty

Ez LINQ Noob Question

How can I make this return a true/false? Is there a way to clean this up without adding a .Count() > 0 call?
bool onlyContainsQuarters = allDates.Where(x => quarterEndMonths.Any(prefix => x.StartsWith(prefix)));
bool onlyContainsQuarters = allDates.Where(x => quarterEndMonths.Any(prefix => x.StartsWith(prefix)));
6 Replies
Natty
NattyOP•2y ago
quarterEndMonths is a hashset of prefixes.
RDasher
RDasher•2y ago
Would this not work?:
bool onlyContainsQuarters = allDates.Any(x => quarterEndMonths.Any(prefix => x.StartsWith(prefix)));
bool onlyContainsQuarters = allDates.Any(x => quarterEndMonths.Any(prefix => x.StartsWith(prefix)));
TheRanger
TheRanger•2y ago
replace Where with Any i think
Natty
NattyOP•2y ago
yea thats what i was actually just typing up lol thanks guys
TheRanger
TheRanger•2y ago
ah someone beat me
Natty
NattyOP•2y ago
just caught it too 😛 these LINQ still sometimes get me for sure appreciate it all
Want results from more Discord servers?
Add your server