ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

Repeat

Repeats a character a given number of times, a little cleaner shortcut than using the string constructor.

Source

/// <summary>
/// Utility class for string manipulation.
/// </summary>
public static class CharExtensions
{
	/// <summary>
	/// Repeat the given char the specified number of times.
	/// </summary>
	/// <param name="input">The char to repeat.</param>
	/// <param name="count">The number of times to repeat the string.</param>
	/// <returns>The repeated char string.</returns>
	public static string Repeat(this char input, int count)
	{
		return new string(input, count);
	}
}

Example

// write a line of 80 -'s to screen:
Console.WriteLine('-'.Repeat(80));

Author: James Michael Hare (BlackRabbitCoder)

Submitted on: 14 okt. 2010

Language: C#

Type: System.Char

Views: 5380