-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConcatenation.Repeat.cs
More file actions
21 lines (19 loc) · 934 Bytes
/
Concatenation.Repeat.cs
File metadata and controls
21 lines (19 loc) · 934 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
namespace TheElm.Literals {
public static partial class Concatenation {
/// <summary>Create a repeating string using a string</summary>
/// <param name="string"></param>
/// <param name="repeat"></param>
/// <returns></returns>
public static string Repeat(this string @string, int repeat)
=> repeat <= 0 ? string.Empty : string.Concat(Enumerable.Repeat(@string, repeat));
/// <summary>Create a repeating string using a char</summary>
/// <param name="character"></param>
/// <param name="repeat"></param>
/// <returns></returns>
public static string Repeat(this char character, int repeat) {
if (repeat < 0)
throw new ArgumentOutOfRangeException(nameof(repeat), $"Not possible to repeat '{character}' {repeat} times.");
return new string(character, repeat);
}
}
}