ListExtensionsReplaceRangeT Method

Removes count amount of items from the target IListT at the specified index, and inserts the specified collection at the same position. The number of elements in collection can be different from the amount of removed items.


Namespace: KGySoft.CoreLibraries
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 8.2.0
public static void ReplaceRange<T>(
	this IList<T> target,
	int index,
	int count,
	IEnumerable<T> collection


target  IListT
The target collection.
index  Int32
The zero-based index of the first item to remove and also the index at which collection items should be inserted.
count  Int32
The number of items to remove.
collection  IEnumerableT
The collection to insert into the target list.

Type Parameters

The type of the elements in the collections.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IListT. 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).



If target is neither a ListT or an ISupportsRangeListT implementation, then after overwriting the elements of the overlapping range, the difference will be removed or inserted one by one.


ArgumentNullExceptiontarget or collection is .
ArgumentOutOfRangeExceptionindex is not a valid index in the CircularListT.

See Also