Thursday, January 10, 2008

c# Performance snippet - Using static string.equals

When comparing two strings it is recommended to it using the string.equals static function. The reason is that this function performs some short circuit checks before actually going to compare each character. For example if you are writing some generic code that will possibly get null as one of the strings the function will use this to perform more quickly. Also if you send the same two strings a reference matching will be found saving you the binary character comparison.

No comments: