(#42) Validate count >=0

This commit is contained in:
Oliver Booth 2021-06-27 13:11:03 +01:00
parent e8ef1cd028
commit e3d38a633d
1 changed files with 9 additions and 2 deletions

View File

@ -1,4 +1,6 @@
namespace X10D
using System;
namespace X10D
{
/// <summary>
/// Extension methods for <see cref="char" />.
@ -15,7 +17,12 @@
/// </returns>
public static string Repeat(this char value, int count)
{
return new(value, count);
if (count < 0)
{
throw new ArgumentOutOfRangeException(nameof(count), ExceptionMessages.CountMustBeGreaterThanOrEqualTo0);
}
return new string(value, count);
}
}
}