Click or drag to resize
EnumerableExPublishTSource Method (IEnumerableTSource)
Creates a buffer with a view over the source sequence, causing each enumerator to obtain access to the remainder of the sequence from the current index in the buffer.

Namespace: System.Linq
Assembly: System.Interactive (in System.Interactive.dll) Version: 1.2.0.0
Syntax
C#
public static IBuffer<TSource> Publish<TSource>(
	this IEnumerable<TSource> source
)

Parameters

source
Type: System.Collections.GenericIEnumerableTSource
Source sequence.

Type Parameters

TSource
Source sequence element type.

Return Value

Type: IBufferTSource
Buffer enabling each enumerator to retrieve elements from the shared source sequence, starting from the index at the point of obtaining the enumerator.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerableTSource. 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).
Examples
var rng = Enumerable.Range(0, 10).Publish(); var e1 = rng.GetEnumerator(); // e1 has a view on the source starting from element 0 Assert.IsTrue(e1.MoveNext()); Assert.AreEqual(0, e1.Current); Assert.IsTrue(e1.MoveNext()); Assert.AreEqual(1, e1.Current); var e2 = rng.GetEnumerator(); Assert.IsTrue(e2.MoveNext()); // e2 has a view on the source starting from element 2 Assert.AreEqual(2, e2.Current); Assert.IsTrue(e1.MoveNext()); // e1 continues to enumerate over its view Assert.AreEqual(2, e1.Current);
See Also