Pads a sequence with a given filler value if it is narrower (shorter
in length) than a given width.
Declaration Syntax
C# | Visual Basic | Visual C++ |
public static IEnumerable<TSource> Pad<TSource>( this IEnumerable<TSource> source, int width, TSource padding )
<ExtensionAttribute> _ Public Shared Function Pad(Of TSource) ( _ source As IEnumerable(Of TSource), _ width As Integer, _ padding As TSource _ ) As IEnumerable(Of TSource)
public: [ExtensionAttribute] generic<typename TSource> static IEnumerable<TSource>^ Pad( IEnumerable<TSource>^ source, int width, TSource padding )
Generic Template Parameters
- TSource
- The type of the elements of source.
Parameters
- source (IEnumerable<(Of <(<'TSource>)>)>)
- The sequence to pad.
- width (Int32)
- The width/length below which to pad.
- padding (TSource)
- The value to use for padding.
Return Value
Returns a sequence that is at least as wide/long as the width/length
specified by the width parameter.
Usage Note
In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerable<(Of <(<'TSource>)>)>. When you use instance method syntax to call this method, omit the first parameter.
Remarks
This operator uses deferred execution and streams its results.
Examples
Copy | |
---|---|
int[] numbers = { 123, 456, 789 }; IEnumerable<int> result = numbers.Pad(5, -1); |
Assembly: MoreLinq (Module: MoreLinq.dll) Version: 1.0.16006.0 (1.0.16006.1845)