If A=C and B=D, then AB becomes CD by substitution, and CD=CD is an identity statement.
If A=D and B=C, then AB becomes DC by substitution. But DC is represented by a line joining two points, and the line measures the same which ever is the starting point or ending point. It is still simply the distance between them. So DC=CD, therefore AB=CD and CD is identical with itself. So the statement is true for both conditions.