Showing posts with label string. Show all posts
Showing posts with label string. Show all posts

Thursday, January 10, 2008

c# Performance snippet - checking if a string is null

Best practice for checking if the string is null is by (string.length == 0). It is more than 2 times faster than comparing to string.empty

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.