EnumerableExtensionsTryRemoveRangeT(IEnumerableT, 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: 8.1.0
C#
public static bool TryRemoveRange<T>(
	this IEnumerable<T> collection,
	int index,
	int count,
	bool checkReadOnlyAndBounds = true,
	bool throwError = true
)

Parameters

collection  IEnumerableT
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: .

Type Parameters

T
The type of the elements in the collections.

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 IEnumerableT. 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.

See Also