EnumerableExtensionsTryRemoveRange(IEnumerable, Int32, Int32, Boolean, Boolean) Method

Tries to remove count amount of items from the specified collection at the specified index.


Namespace: KGySoft.CoreLibraries
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 8.2.0
public static bool TryRemoveRange(
	this IEnumerable collection,
	int index,
	int count,
	bool checkReadOnlyAndBounds = true,
	bool throwError = true


collection  IEnumerable
The collection to remove the elements from.
index  Int32
The zero-based index of the first item to remove.
count  Int32
The number of items to remove.
checkReadOnlyAndBounds  Boolean  (Optional)
to return if the target collection is read-only or the index is invalid; to attempt inserting the collection without checking the read-only state and bounds. This parameter is optional.
Default value: .
throwError  Boolean  (Optional)
to forward any exception thrown by a found remove method; to suppress the exceptions thrown by the found remove method and return on failure. This parameter is optional.
Default value: .

Return Value

, if the whole range could be removed from collection; otherwise, .

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerable. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).


Removal is supported if collection is either an IListT or IList implementation.


If collection is neither a ListT nor an ISupportsRangeListT implementation, then the elements will only be removed one by one.


Whenever possible, try to use the generic TryRemoveRange<T> overload for better performance.

See Also