Standard Type Casting and "as" Operator Conversions
page 5 of 5
by Brendan Enrick
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 28116/ 58


Working with conversion of types in C# is not all that complicated. We have looked at standard casting as well as using the "as" operator to convert between types. Keep in mind the importance of reference types with the "as" operator, and try to only use it when there is a high likelihood that the conversion will not work or if the failure to convert is not an error. If the situation is unlikely to occur, then you should cast the object and handle the exception. This way you make sure that you are actually taking care of the error if it occurs.

Read more from this author on his blog.

View Entire Article

User Comments

Title: hjk   
Name: hgjk
Date: 2012-06-14 2:05:34 AM
Title: Thank you for your help.   
Name: Jose Amayo
Date: 2009-10-30 12:16:52 PM
Hello Brendan,
Thank you very much for taking the time to write this article and the one explaining the difference between value and reference types. They were invaluable in helping me tweak an ASP.NET project I am working on.

Community Advice: ASP | SQL | XML | Regular Expressions | Windows

©Copyright 1998-2022  |  Page Processed at 2022-09-30 10:45:50 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search