Help me please

BeginnnnnerBeginnnnner Member ✭✭

I have 2 classes (PlayerName and Action), in PlayerName there is a string called name (text from edittext) and I need to transfer the string to the other class Action, where I will work with the name later (I put there a switch, just to show I need to work with the chosen name from class PlayerName)


public void PlayerName()
{
EditText player1 = FindViewById(Resource.Id.player1);
string name = player1.Text;
}

public void Action()
{
string playername = name from class PlayerName;
switch (playername)
{
case "George":
some code will be here;
break;

case "Jack":
some code will be here;
break;
}

This may sound stupid for you, but I'm beginner in programming. How can I transfer the string from one class to the other?

Tagged:

Answers

  • ChandanGuptaChandanGupta USMember
    edited January 4

    First of all you need to know the concept of OOP (Object Oriented Programming). I think you might be saying Methods instead of Classes.
    Do look to the basics of OOP. There are tons of examples where you can get the idea.

    Have a look at this.

    I think you might be looking for this.
    public class ClassName
    {
    string name;
    public void PlayerName()
    {
    EditText player1 = FindViewById(Resource.Id.player1);
    name = player1.Text;
    }

                public void Action()
                {
                    string playername = name 
                    switch (playername)
                    {
                        case "George":
                        //some code will be here;
                        break;
    
                        case "Jack":
                        //some code will be here;
                        break;
                    }
                }
            }
    
Sign In or Register to comment.