-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
[API Proposal]: ArgumentOutOfRangeException.ThrowIfNegativeOrGreaterThanOrEqual #82930
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
I think we don't need |
Tagging subscribers to this area: @dotnet/area-system-runtime Issue DetailsBackground and motivationFor the common case of validating an index to a span, array, string, etc. Can be implemented in one branch as ArgumentOutOfRangeException.ThrowIfNegative(arrayIndex);
ArgumentOutOfRangeException.ThrowIfGreaterThan(arrayIndex, array.Length); API Proposalnamespace System
public class ArgumentOutOfRangeException : ArgumentException
{
public static void ThrowIfNegativeOrGreaterThan<T>(T value, T other, [CallerArgumentExpression(nameof(value))] string? paramName = null)
where T : INumberBase<T>
public static void ThrowIfNegativeOrGreaterThanOrEqual<T>(T value, T other, [CallerArgumentExpression(nameof(value))] string? paramName = null)
where T : INumberBase<T>
} API Usage private T[] array
public T this[int arrayIndex]
{
get
{
ArgumentOutOfRangeException.ThrowIfNegativeOrGreaterThanOrEqual(arrayIndex, array.Length);
return array[arrayIndex];
}
} Alternatives
|
This comment was marked as duplicate.
This comment was marked as duplicate.
In my own libraries, I use the name |
This issue has been marked |
Note that #77749 proposes a |
This issue has been automatically marked |
This issue will now be closed since it had been marked |
Background and motivation
For the common case of validating an index to a span, array, string, etc.
Can be implemented in one branch as
(uint)value >= (uint)other
as opposed to two branches with the following:API Proposal
API Usage
Alternatives
The text was updated successfully, but these errors were encountered: