SweUser
SweUser

Reputation: 101

Why does this bool not recognize being used?

I've made an example of typing in first and last name. Why doesn't the assigned variable "EmptyInput" recognize it's being used even though I've added a false and true value? I don't know what the green wavy line underneath is called.

using System.Collections.Generic;
using System;
using System.Threading;

namespace MyLogbook
{
    public static class Program
    {
        class PInfo
        {
            public string FirstName;
            public string LastName;
        }
        public static void Main(string[] args)
        {

        Console.WriteLine("\tWelcome to your new logbook!");
            Console.WriteLine("\tPlease enter your first and last name.\n");

            PInfo pInfo = new PInfo();
            bool EmptyInput;
            do
            {
                Console.Write("\tFirst name: ");
                pInfo.FirstName = Console.ReadLine();

                Console.Write("\tLast name: ");
                pInfo.LastName = Console.ReadLine();

                if (!string.IsNullOrEmpty(pInfo.FirstName + pInfo.LastName))
                {
                    Console.WriteLine("\n\tHi, " + pInfo.FirstName + " " + pInfo.LastName + ".\n");
                    EmptyInput = false;
                }
                else
                {
                    Console.Write("\n\tEmpty input, please try again.\n\n");
                    EmptyInput = true;
                }
            } while (string.IsNullOrEmpty(pInfo.FirstName + pInfo.LastName));
        }
    }
}

Upvotes: 0

Views: 118

Answers (1)

user14320959
user14320959

Reputation: 44

Maybe you mean to do this

} while (EmptyInput);

instead of

} while (string.IsNullOrEmpty(pInfo.FirstName + pInfo.LastName));

because you're just assigning value to the variable, but never using it

Upvotes: 2

Related Questions