throw new ArgumentOutOfRangeException(nameof(arrayIndex), arrayIndex, SR.ArgumentOutOfRange_Index);
}
- int arrayLen = array.Length;
- if (arrayLen - arrayIndex < _size)
+ if (array.Length - arrayIndex < _size)
{
throw new ArgumentException(SR.Argument_InvalidOffLen);
}
{
if (_size == _array.Length)
{
- int newcapacity = (int)((long)_array.Length * (long)GrowFactor / 100);
+ int newcapacity = (int)(_array.Length * (long)GrowFactor / 100);
if (newcapacity < _array.Length + MinimumGrow)
{
newcapacity = _array.Length + MinimumGrow;
public void TrimExcess()
{
- int threshold = (int)(((double)_array.Length) * 0.9);
+ int threshold = (int)(_array.Length * 0.9);
if (_size < threshold)
{
SetCapacity(_size);
ICollection IDictionary.Keys
{
- get { return (ICollection)Keys; }
+ get { return Keys; }
}
ICollection IDictionary.Values
{
- get { return (ICollection)Values; }
+ get { return Values; }
}
object? IDictionary.this[object key]
throw new ArgumentNullException(nameof(key));
}
- if (value == null && !(default(TValue) == null))
+ if (value == null && default(TValue) != null)
throw new ArgumentNullException(nameof(value));
try
throw new ArgumentNullException(nameof(key));
}
- if (value == null && !(default(TValue) == null))
+ if (value == null && default(TValue) != null)
throw new ArgumentNullException(nameof(value));
try
throw new ArgumentException(SR.Arg_ArrayPlusOffTooSmall);
}
- TKey[]? keys = array as TKey[];
- if (keys != null)
+ if (array is TKey[] keys)
{
CopyTo(keys, index);
}
throw new ArgumentException(SR.Arg_ArrayPlusOffTooSmall);
}
- TValue[]? values = array as TValue[];
- if (values != null)
+ if (array is TValue[] values)
{
CopyTo(values, index);
}
public sealed class TreeSet<T> : SortedSet<T>
{
public TreeSet()
- : base()
{ }
public TreeSet(IComparer<T>? comparer) : base(comparer) { }
if (key == null)
throw new ArgumentNullException(nameof(key));
- if (value == null && !(default(TValue) == null)) // null is an invalid value for Value types
+ if (value == null && default(TValue) != null) // null is an invalid value for Value types
throw new ArgumentNullException(nameof(value));
if (!(key is TKey))
throw new ArgumentException(SR.Arg_ArrayPlusOffTooSmall);
}
- KeyValuePair<TKey, TValue>[]? keyValuePairArray = array as KeyValuePair<TKey, TValue>[];
- if (keyValuePairArray != null)
+ if (array is KeyValuePair<TKey, TValue>[] keyValuePairArray)
{
for (int i = 0; i < Count; i++)
{
}
set
{
- if (((object)key) == null) throw new ArgumentNullException(nameof(key));
+ if (key == null) throw new ArgumentNullException(nameof(key));
int i = Array.BinarySearch<TKey>(keys, 0, _size, key, comparer);
if (i >= 0)
{
throw new ArgumentNullException(nameof(key));
}
- if (value == null && !(default(TValue) == null))
+ if (value == null && default(TValue) != null)
throw new ArgumentNullException(nameof(value));
TKey tempKey = (TKey)key;
// SortedList.TrimExcess();
public void TrimExcess()
{
- int threshold = (int)(((double)keys.Length) * 0.9);
+ int threshold = (int)(keys.Length * 0.9);
if (_size < threshold)
{
Capacity = _size;
public int IndexOf(TKey key)
{
- if (((object)key) == null)
+ if (key == null)
throw new ArgumentNullException(nameof(key));
int i = Array.BinarySearch<TKey>(_dict.keys, 0,
// The .NET Foundation licenses this file to you under the MIT license.
using System.Diagnostics;
-using System.Diagnostics.CodeAnalysis;
using System.Runtime.Serialization;
namespace System.Collections.Generic
BreadthFirstTreeWalk(n => { toRemove.Add(n.Item); return true; });
while (toRemove.Count != 0)
{
- _underlying.Remove(toRemove[toRemove.Count - 1]);
+ _underlying.Remove(toRemove[^1]);
toRemove.RemoveAt(toRemove.Count - 1);
}
public void TrimExcess()
{
- int threshold = (int)(((double)_array.Length) * 0.9);
+ int threshold = (int)(_array.Length * 0.9);
if (_size < threshold)
{
Array.Resize(ref _array, _size);