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

Conclusion

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
Comment:
hhjkghjkjhk
Title: Thank you for your help.   
Name: Jose Amayo
Date: 2009-10-30 12:16:52 PM
Comment:
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-2024 ASPAlliance.com  |  Page Processed at 2024-03-29 11:31:47 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search