Method Intersperse
Intersperse<T>(IEnumerable<T>, Func<T, T>)
Inserts a specified separator between each element of a sequence, if the sequence has more than one item.
Declaration
public static IEnumerable<T> Intersperse<T>(this IEnumerable<T> items, Func<T, T> separatorFactory)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | items | The sequence into which the separator will be interspersed. |
| Func<T, T> | separatorFactory | The element factory which will be used to intersperse in between the elements of the sequence. |
Returns
| Type | Description |
|---|---|
| IEnumerable<T> | A sequence that contains the elements of the input sequence with the separator interspersed between each element. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the elements of the input sequence. |
Remarks
If the sequence is empty or contains only one element, the returned sequence will be equivalent to the input sequence.
Intersperse<T>(IEnumerable<T>, T)
Inserts a specified separator between each element of a sequence, if the sequence has more than one item.
Declaration
public static IEnumerable<T> Intersperse<T>(this IEnumerable<T> items, T separator)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | items | The sequence into which the separator will be interspersed. |
| T | separator | The element to intersperse in between the elements of the sequence. |
Returns
| Type | Description |
|---|---|
| IEnumerable<T> | A sequence that contains the elements of the input sequence with the separator interspersed between each element. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the elements of the input sequence. |
Remarks
If the sequence is empty or contains only one element, the returned sequence will be equivalent to the input sequence.