tryparse returning 0

have i got the idea of tryparse wrong, i am trying to convert an int to string then back to int but it only returns 0, anyone got any idea how this works, i need the converted int to match the original int after conversion

code below thanks

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class INTTOHEXCHECK2 : MonoBehaviour {


    public int Score;

    private int myNewInt;

    // Use this for initialization
    void Start () {


        string myHex = Score.ToString("X");


        int.TryParse(myHex, out myNewInt);   //  ONLY RESULTS CONVERTING TO 0


        Debug.Log("Score "+ Score + "   HEX "+ myHex + "   BACKTOINT "+ myNewInt);



       
       
    }
   

}

you are converting to hexadecimal, it might contain letters. (then int parse fails).
try printing out the “myHex” to check,
also int.TryParse() returns true or false, can check that too.

or look for code to convert hex value into integer.

why you need to convert int to string and back?

You need to use this code:

string hexString = "8E2";
int num = Int32.Parse(hexString, System.Globalization.NumberStyles.HexNumber);
Console.WriteLine(num);
//Output: 2274

Taken from here: How to convert between hexadecimal strings and numeric types - C# | Microsoft Learn

Not sure if TryParse supports numberstyles. If it does I would use TryParse, otherwise wrap it in a try/catch block.

codesmile thanks, but getting error "
The name `Int32’ does not exist in the current context

am i missing a using directive at top of script?

if you know its hex you could write your own… do it character by character

Just prefix it with System.Int32 or change Int32 to int. These are synonymous.

thanks works like a charm, regards