Friday, June 24, 2011

Extension method (2)

In my previous article, I have created an extension method call StrToInt for String class. Now, the question is what if a string object instance is null value and it's calling the extension method? Will the program crash? The answer is NO.

Try this out:

string s = null;
int i = s.StrToInt();