When we execute the above program, it also gives us the same NULL Reference exception as shown below. This is because the Name variable is Null and we are invoking the ToString method. Let see what happens when we use the Convert. Tostring method with the above two examples. Now, with the above changes, run the application and it should be executed without any error. So in short, the Convert. ToString method will take care of the Null values and it is also safe to use.
In the next article onwards, I am going to discuss checked and unchecked keywords in C with examples. Sign in Email. Forgot your password? Ask a Question. Purpose of Convert.
Tostring and. Please Sign up or sign in to vote. See more: C. ToSring and. Thanking U. Posted Jul pm Shekar Raja. Add a Solution. Top Rated Most Recent. Accept Solution Reject Solution. ToString it will handle the null exceptions and using. ToString It won't handle the null exceptions. Copy Code. Posted Jul pm Rajesh Varma Buddaraju. Hi Sheker, Main difference is each class base class is Object class, and object class has few methods and ToString is one of them you can write overload and override.
So when you call object. ToString its mean it will call that objects ToString there for if object is null then it will throw an exception Object is not set to an instance of an object. Where as In Convert. Subscribe to: Post Comments Atom. Interview Questions in ASP. NET Framework Simple login form example in asp. Search This Site. Get Latest articles in your inbox for free. Enter your email address:. Tags Asp. Net General VB. All Rights Reserved. The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.
Suresh Dasari View my complete profile.
0コメント