Is there any performance optimization in below code samples where I compare two string?
First:
public static bool Compare_01()
{
    string str_01 = "a";
    string str_02 = "a";
    if (str_01 == str_02)
        return true;
    else
        return false;
}
Two:
public static bool Compare_02()
{
    string str_01 = "a";
    string str_02 = "a";
    if ((object)str_01 == (object)str_02)
        return true;
    else
        return false;
}
Both of them return true.
There is only one different in their il code:
1st:
IL_0001:  ldstr       "a"
IL_0006:  stloc.0     // str_01
IL_0007:  ldstr       "a"
IL_000C:  stloc.1     // str_02
IL_000D:  ldloc.0     // str_01
IL_000E:  ldloc.1     // str_02
IL_000F:  call        System.String.op_Equality
2nd:
IL_0001:  ldstr       "a"
IL_0006:  stloc.0     // str_01
IL_0007:  ldstr       "a"
IL_000C:  stloc.1     // str_02
IL_000D:  ldloc.0     // str_01
IL_000E:  ldloc.1     // str_02
IL_000F:  ceq         
I found something like this in System.String:
public static bool Equals(String a, String b) {
    // Here
    if ((Object)a==(Object)b) {
        return true;
    }
    // ****
    if ((Object)a==null || (Object)b==null) {
        return false;
    }
    if (a.Length != b.Length)
        return false;
    return EqualsHelper(a, b);
}
				
                        
Your version "Two" does something different: it compares for reference equality (you can see this in the
ceqin the IL you added in an edit). This will often work in basic tests, due to string interning - but it should not be relied upon. It is working by accident only.Basically, just use:
This is the idiomatic way of expressing "compare these two strings for equality", and it will be inlined to a call to
string.Equals(string a, string b)anyway.