Please help me with the task: First name and last name validator

Hello, I’m working on this task:

Write a program that reads a user’s first name and last name from the console input (each on its own line). Both names must not be empty and must consist of two characters or more. If a user inputs an empty string for the first name, you should output “First name can’t be empty! Try again.” Same for the last name: “Last name can’t be empty! Try again.” If the first name is only one character long, the program should output: “First name is too short! Try again.” and the same for last name: “Last name is too short! Try again.” The program should ask for and read the first and last name until the user inputs valid values for both. Then it should print “My greetings, {firstName} {lastName}!” For example:
>
>Walker
First name can’t be empty! Try again.

>Alan
>
Last name can’t be empty! Try again.

>
>
First name can’t be empty! Try again.
Last name can’t be empty! Try again.

>Alan
>W
Last name is too short! Try again.

>Alan
>Walker
My greetings, Alan Walker!

Here is my code:


namespace InputValidation
{
   class IDontEvenKnowMyName
   {
       static void Main(string[] args)
       {
           var firstName = Console.ReadLine();
           var secondName = Console.ReadLine();

           while (string.IsNullOrEmpty(firstName) || string.IsNullOrEmpty(secondName) || firstName.Length == 1 || secondName.Length == 1)
           {

               if (string.IsNullOrEmpty(firstName))
               {
                   Console.WriteLine("First name can't be empty! Try again.");
                   firstName = Console.ReadLine();
               }

               else if (firstName.Length == 1)
               {
                   Console.WriteLine("First name is too short! Try again.");
                   firstName = Console.ReadLine();
               }

               if (string.IsNullOrEmpty(secondName))
               {
                   Console.WriteLine("Last name can't be empty! Try again.");
                   secondName = Console.ReadLine();
               }

               else if (secondName.Length == 1)
               {
                   Console.WriteLine("Last name is too short! Try again.");
                   secondName = Console.ReadLine();
               }
           }
       
           Console.WriteLine($"My greetings, {firstName} {secondName}!");
       }
   }
}

Can anyone please help me to solve it?

Hey, your code is amazing! The program wants the user to have to input both the first and last name every time so your readlines have to be outside of the if statements like below:

while ((string.IsNullOrEmpty(firstName)) || (string.IsNullOrEmpty(secondName)) || (firstName.Length == 1) || (secondName.Length == 1)) {

            if (string.IsNullOrEmpty(firstName)) {
               Console.WriteLine("First name can't be empty! Try again.");
            } else if (firstName.Length == 1) {
               Console.WriteLine("First name is too short! Try again.");
            }

            if (string.IsNullOrEmpty(secondName)) {
               Console.WriteLine("Last name can't be empty! Try again.");
            } else if (secondName.Length == 1) {
               Console.WriteLine("Last name is too short! Try again.");
            }

            firstName = Console.ReadLine();
            secondName = Console.ReadLine();
        }

Hey, thanks for the reply, I rewrote it and it ended up working!