Why == works in an if statement?

Also, it's a good habit to put the constant before the variable it's being compared to.
i.e.

if (25 == a)
{
    // Some action here
}

The reason for doing this,

if (25 = a)
{
}

Will cause a compiler error. Because you're trying to assign a variable to a constant. This coding habit will catch your error where, if you put = but meant == (a very common mistake). If you do a = 25 it will compile, but obviously not what was intended.