Wednesday, April 11, 2012

C#.NET - Difference between Convert.ToString(), .ToString(), and (string) cast

Convert.ToString(), .ToString() and (string)
All these are used for converting an object into a string, but they differ the way they handle NULL values.

>> Convert.ToString() returns String.Empty while attempting to convert a NULL object into a string.
>> .ToString() throws an exception in such cases
>> While, (string) cast sets a string variable as "null" value, and do not throw any exception, but if you try to access any property, method it throws an exception.

No comments:

Post a Comment

Thanks for visiting my blog.
However, if this helped you in any way, please take a moment to write a comment.

Thanks
Nirman

Blog Archive