Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: int.OutOfRange that takes a collection as parameter #66

Open
DrHeinzDoofenshmirtz opened this issue Nov 26, 2022 · 3 comments

Comments

@DrHeinzDoofenshmirtz
Copy link

Hi.
I would like to suggest a throw extension to integer values to check if the integer is within the range of a given collection.
At the moment (as far as I know), I have to write 0 for min-value and collection.Count - 1 for max value.

@amantinband
Copy link
Owner

Something like the following:

10.Throw().IfOutOfRange(0, 100)

?

@DrHeinzDoofenshmirtz
Copy link
Author

DrHeinzDoofenshmirtz commented Apr 26, 2023

I was more thinking:

var collection = Some list or whatever;
10.Throw().IfOutOfRange(collection)

Behind the scenes the method uses 0 and collection.Count/Length - 1 to make a check like the one you are mentioning.

The purpose is to just check if you receive an index value that is within the size of a collection.

@ayodejii
Copy link

ayodejii commented Apr 9, 2024

i'm not sure if this is implemented already, but i think it should be the other way round, i.e. the collection should check if the index value is within its range.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants