diff --git a/examples/dotnet/Program.cs b/examples/dotnet/Program.cs index baaebea2..bb889594 100644 --- a/examples/dotnet/Program.cs +++ b/examples/dotnet/Program.cs @@ -1,3 +1,4 @@ + namespace ConsoleApp { using System; @@ -41,8 +42,27 @@ static void Main() /// private static string GetCompeFromUser() { - Console.Write("Buscar COMPE (3 dígitos): "); - return Console.ReadLine(); + string compe; + do + { + Console.Write("Buscar COMPE (3 dígitos): "); + compe = Console.ReadLine(); + } while (!IsValidCompe(compe)); + + return compe; + } + + /// + /// Validates if the given is a valid COMPE code. + /// + /// A string representing the COMPE code to validate. + /// + /// if the is exactly 3 characters long + /// and consists only of numeric digits; otherwise, . + /// + private static bool IsValidCompe(string compe) + { + return compe.Length == 3 && compe.All(char.IsDigit); } ///