Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adição de um novo método IsValidCompe no arquivo Program.cs #582

Merged
merged 6 commits into from
Nov 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions examples/dotnet/Program.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

namespace ConsoleApp
{
using System;
Expand Down Expand Up @@ -41,8 +42,27 @@ static void Main()
/// </remarks>
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;
}

/// <summary>
/// Validates if the given <paramref name="compe"/> is a valid COMPE code.
/// </summary>
/// <param name="compe">A string representing the COMPE code to validate.</param>
/// <returns>
/// <see langword="true"/> if the <paramref name="compe"/> is exactly 3 characters long
/// and consists only of numeric digits; otherwise, <see langword="false"/>.
/// </returns>
private static bool IsValidCompe(string compe)
{
return compe.Length == 3 && compe.All(char.IsDigit);
}

/// <summary>
Expand Down
Loading