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

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

Definition

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

Parameters

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

Boolean
, 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).

Remarks

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

  Note

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

  Note

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

See Also