krisgithub1234 / linqbridge

Automatically exported from code.google.com/p/linqbridge
Other
0 stars 0 forks source link

ElementAtOrDefault should never throw ArgumentOutOfRangeException #14

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. ElementAtOrDefault(-1) throws ArgumentOutOfRangeException
2. IList.ElementAtOrDefault(x) throws ArgumentOutOfRangeException if argument x 
is not in a valid range. 

What is the expected output? What do you see instead?
The result should be default(T)

What version of the product are you using? On what operating system?
1.2

Please provide any additional information below.
Tested behaviour against .NET and its not consistent. .NET Linq does not 
through ArgumentOutOfRangeException in any of the 2 cases above.

Original issue reported on code.google.com by kevinkn...@gmail.com on 19 Oct 2010 at 1:45

GoogleCodeExporter commented 9 years ago
> What version of the product are you using?
> 1.2

Is the 1.2 a typo? The most current release at the time this issue was reported 
was 1.1. I checked against version 1.1 and ElementAtOrDefault does not throw 
ArgumentOutOfRangeException. You can see from line 588 on of Enumerable.cs [1] 
that the implementation specifically handles a negative index to return 
default(T). It also does this when the index is greater than or equal to the 
count of items in the list. Attached is a complete solution that tried to 
reproduce the problem but it does not demonstrate the reported behavior.

[1] 
http://code.google.com/p/linqbridge/source/browse/tags/REL-1.1/src/Enumerable.cs
#588

Original comment by azizatif on 19 Oct 2010 at 8:57

Attachments:

GoogleCodeExporter commented 9 years ago
Apologies, I was working with 1.0.2. The latest version works correctly.
Regards

Original comment by kevinkn...@gmail.com on 20 Oct 2010 at 5:26