Question How to modify string from a class

NeoSki

New member
Joined
Mar 9, 2021
Messages
1
Programming Experience
1-3
Hello, I wish to modify the string name from the method username, but it doesn't seem to work with the below code:

C#:
class Program
    {
        //string to modify
        string name = null;

        public void username()
        {
            Console.Clear();

            //Get user name
            Console.Write("\nWhat's your name? ");

            //edit string - doesn't work?
            string name = Console.ReadLine();

            Console.Clear();

            return;
        }
    }
 
You're creating a new local variable in line 14 instead of assigning to the one declared in line 4.
 
Back
Top Bottom