[Closed]String.Equals returns false everytime

I want to check if the first letter of the name of the gameobject equals T.
I wrote following

   if(string.Equals(other.gameObject.transform.parent.gameObject.name[0],"T")){
       DoStuff;
    }
    Debug.Log ("(T)("+other.gameObject.transform.parent.gameObject.name[0]+")");

The Debuglog says (T)(T) but it never goes into the If method.

The problem is that name[0] is a char data type, but you’re comparing it to a string. Equals only return true if the data types match.

Change “T” to ‘T’ and it should work fine.

Just check with the ‘==’ sign:

    if(other.gameObject.transform.parent.gameObject.name[0]=='T')){
        //Code
     }