C# int to string

Hey,

I’m having a bit of trouble converting an int to a string for use in print function.

        string levelString = levelEngine.return_level();
        // Set the amount of gems there are in the level.
        switch(levelString)
        {
            case "level1":
            gems  = 12;
            print(gems.ToString());
            break;

        }
    }

I’m getting an error that says can’t implicitly convert int to string.

Whenever you mention an error you should point out which line is causing it.

In this case, levelEngine.return_level returns an int, but you are trying to assign it to a string. You need to convert the int to a string by adding .ToString ().

string levelString = levelEngine.return_level().ToString ();
1 Like

thanks :)… I solved this too. You were right, just returned the wrong value and I wasn’t paying attention to where the error was coming from.