How do I change the value of the string in C#?

Copper Knight

Playing around in C# trying to make a name input system but none of the code within my while loop affects the code outside it. First part of the code works perfectly but when entering the loop I cant manage to change any of the values which effectively traps me within it. pls help.

class name
        {
            public static string nameTag;
        }
        class oK
        {
            public static string nameBool;
        }
        static void Main(string[] args)
        {
          Console.WriteLine("Whats your Name?");
            string nameTag = Console.ReadLine();
            Console.WriteLine(nameTag + ", is that correct?");
            string nameBool = Console.ReadLine();

            if(nameBool=="no")
            {
                
                while (nameBool=="no")
                {
                    name.nameTag = String.Empty;
                    name.nameTag = Console.ReadLine();
                    Console.WriteLine(nameTag + ", is that correct?");
                    oK.nameBool = String.Empty;
                    oK.nameBool = Console.ReadLine();

                }
}
}
Ibrennan208

In your code above, you have static classes defined when you could just be using a variable.

Here is some of your code tidied up (Notice nameTag and nameBool are only defined once):

public class Example
{
    public static void Main(string[] args)
    {
        Console.WriteLine("Whats your Name?");
        string nameTag = Console.ReadLine();
        Console.WriteLine(nameTag + ", is that correct?");
        string nameBool = Console.ReadLine();

        while (nameBool == "no")
        {
            nameTag = Console.ReadLine();
            Console.WriteLine(nameTag + ", is that correct?");
            nameBool = Console.ReadLine();
        }
    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I change the value of an appended string?

How do I change each char in a string but not change punctuations in C?

How do I change the value of a variable inside a string?

How do I change the color of an infobox in shinydashboard based on a string, not a value?

How do I change a particular int value in an array to a char in C?

How do i insert a value to a string, if i want to change that string's value later, but i want to keep the format?

How do I set a string value inside an if statement? (C++)

How i will change the value in the string in json file?

How do I change the value of a textbox with this JQuery?

How do I change a value in a .npz file?

How Do I Change The Appended Input Value?

How do I change the MTU value on Ubuntu?

How do I change the value of an item in a Set?

How do I change this value using regex?

How do I change a value of a variable in this case?

How do I change the format of a value in a table?

How do I change the value in an array? Mongoose

How do I change the value and save it to a file?

how do i change the value of an object

How do I change a string to a number

JavaScript - How do i change time of string

How do i change the color of an appended string?

In C#, how do I change a Key-Value-Property's value while recursively traversing an ExpandoObject?

How do I change a string value to a timestamp? Javascript React-Native

How do I change part of a string in an attribute value using XSLT with Python and LXML?

How do change the string array in C#

How to do change the string format in c#

How do I use the char value for string?

How do I get the value of a query string?