Search code examples
c#stringlong-integer

C# print long int with string


I can call it properly in the first part of the code this is built into a long list of if else statements.

if (Ten < 0) {
        Ten = x;
    long y = System.Int64.Parse (One + "" + Two + ""//... code continues);
        print ("Press Tab to confirm to play with " + y + ".");
            ChosenNum ();
    } else if (Ten > -1) {
        print ("Press Tab to confirm to play with " + y + ".");
    }

In the code just after and in the function below it doesn't call the long y.

void ChosenNum ()
{
    if (Input.GetKeyDown (KeyCode.Tab)) {
        print ("You have chosen " + y);
        StartGame2 ();
    }
}

I want to call the long y in the code just after and in the function, if I assign long y; at the start of my class It conflicts with my int y; Creating a long w for instance will cause the need for extra code, but would like to find a solution without doing so.


Solution

  • Why don't you simply do this :

    void ChosenNum (long value)
    {
        if (Input.GetKeyDown (KeyCode.Tab)) {
            print ("You have chosen " + value);
            StartGame2 ();
        }
    }
    

    Then call it :

    if (Ten < 0) {
        Ten = x;
    long y = System.Int64.Parse (One + "" + Two + ""//... code continues);
        print ("Press Tab to confirm to play with " + y + ".");
            ChosenNum (y);//pass it here, this is my change
    } else if (Ten > -1) {
        print ("Press Tab to confirm to play with " + y + ".");
    }