Click here to Skip to main content
15,850,685 members
Home / Discussions / C#
   

C#

 
QuestionRe: Exceptions Pin
Eddy Vluggen18-Jan-22 20:32
professionalEddy Vluggen18-Jan-22 20:32 
AnswerRe: Exceptions Pin
lmoelleb18-Jan-22 21:40
lmoelleb18-Jan-22 21:40 
GeneralRe: Exceptions Pin
Eddy Vluggen19-Jan-22 1:40
professionalEddy Vluggen19-Jan-22 1:40 
GeneralRe: Exceptions Pin
lmoelleb19-Jan-22 1:48
lmoelleb19-Jan-22 1:48 
GeneralRe: Exceptions Pin
Eddy Vluggen19-Jan-22 2:12
professionalEddy Vluggen19-Jan-22 2:12 
AnswerRe: Exceptions Pin
Eddy Vluggen18-Jan-22 19:02
professionalEddy Vluggen18-Jan-22 19:02 
AnswerRe: Exceptions Pin
jschell23-Jan-22 8:32
jschell23-Jan-22 8:32 
Questionnecessity to use .Any() to check if an IEnumerable<T> result has no items without iterating over it ? Pin
BillWoodruff16-Jan-22 3:39
professionalBillWoodruff16-Jan-22 3:39 
C# >= 4

Curious to know if you've had to deal with the issues described here.

1) assume you have a generic method of Type T

2) in that method a Func<IEnumerable<T>, IEnumerable<T>> is called on an IEnumerable of T

3) the result of calling the func is in a variable 'temp ... when you examine 'temp in the Command Window at run-time after hitting a break-point:
> ? temp
{System.Linq.Enumerable.WhereListIterator<int>}
    Current: 0
    Results View: Expanding the Results View will enumerate the IEnumerable
> ? temp == null
false
> ? temp == default
false
> ? temp is null
false
> ? temp.Any()
false
> ? temp.Count()
0
4) in the case where the Func call results in no content (no items)

4a) you want to evaluate whether 'temp has any "items" ... i.e., has a Count of #0 (as shown above)

4b) but, you do not want to trigger iteration/enumeration of 'temp by calling Count()

I have read that .Any() will not cause iteration in this very interesting SO thread: [^].

And, on the same thread: [^]: is mention of a new C#6 Linq function 'TryGetNonEnumeratedCount
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch

GeneralRe: necessity to use .Any() to check if an IEnumerable<T> result has no items without iterating over it ? Pin
harold aptroot16-Jan-22 4:21
harold aptroot16-Jan-22 4:21 
GeneralRe: necessity to use .Any() to check if an IEnumerable<T> result has no items without iterating over it ? Pin
BillWoodruff16-Jan-22 6:14
professionalBillWoodruff16-Jan-22 6:14 
GeneralRe: necessity to use .Any() to check if an IEnumerable<T> result has no items without iterating over it ? Pin
harold aptroot16-Jan-22 7:56
harold aptroot16-Jan-22 7:56 
GeneralRe: necessity to use .Any() to check if an IEnumerable<T> result has no items without iterating over it ? Pin
BillWoodruff16-Jan-22 19:22
professionalBillWoodruff16-Jan-22 19:22 
GeneralRe: necessity to use .Any() to check if an IEnumerable<T> result has no items without iterating over it ? Pin
Richard Deeming16-Jan-22 23:45
mveRichard Deeming16-Jan-22 23:45 
GeneralRe: necessity to use .Any() to check if an IEnumerable<T> result has no items without iterating over it ? Pin
BillWoodruff18-Jan-22 2:19
professionalBillWoodruff18-Jan-22 2:19 
GeneralRe: necessity to use .Any() to check if an IEnumerable<T> result has no items without iterating over it ? Pin
Richard Deeming18-Jan-22 2:41
mveRichard Deeming18-Jan-22 2:41 
GeneralRe: necessity to use .Any() to check if an IEnumerable<T> result has no items without iterating over it ? Pin
BillWoodruff18-Jan-22 4:08
professionalBillWoodruff18-Jan-22 4:08 
GeneralRe: necessity to use .Any() to check if an IEnumerable<T> result has no items without iterating over it ? Pin
Richard Deeming18-Jan-22 7:17
mveRichard Deeming18-Jan-22 7:17 
GeneralRe: necessity to use .Any() to check if an IEnumerable<T> result has no items without iterating over it ? Pin
BillWoodruff19-Jan-22 14:58
professionalBillWoodruff19-Jan-22 14:58 
GeneralRe: necessity to use .Any() to check if an IEnumerable<T> result has no items without iterating over it ? Pin
Richard Deeming19-Jan-22 22:43
mveRichard Deeming19-Jan-22 22:43 
GeneralRe: necessity to use .Any() to check if an IEnumerable<T> result has no items without iterating over it ? Pin
BillWoodruff20-Jan-22 5:26
professionalBillWoodruff20-Jan-22 5:26 
GeneralRe: necessity to use .Any() to check if an IEnumerable<T> result has no items without iterating over it ? Pin
harold aptroot16-Jan-22 23:48
harold aptroot16-Jan-22 23:48 
GeneralRe: necessity to use .Any() to check if an IEnumerable<T> result has no items without iterating over it ? Pin
BillWoodruff18-Jan-22 1:49
professionalBillWoodruff18-Jan-22 1:49 
GeneralRe: necessity to use .Any() to check if an IEnumerable<T> result has no items without iterating over it ? Pin
jschell23-Jan-22 8:40
jschell23-Jan-22 8:40 
GeneralRe: necessity to use .Any() to check if an IEnumerable<T> result has no items without iterating over it ? Pin
BillWoodruff25-Jan-22 4:58
professionalBillWoodruff25-Jan-22 4:58 
GeneralRe: necessity to use .Any() to check if an IEnumerable<T> result has no items without iterating over it ? Pin
jschell30-Jan-22 7:22
jschell30-Jan-22 7:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.