|
|
|
|
|
by iramiller
5527 days ago
|
|
Actually you don't want to ever use exception driven development. The use of the as operator is a simple metadata check. Throwing exceptions in .Net is expensive. Just because I felt the need to check my own facts (Friday afternoon?) I wrote a simple console app with two classes Class1 and Class2 : Class1. Using a Stopwatch object I checked the elapsed ticks for an 'as' an 'is' and an invalid cast exception check. 'as' = 5 ticks 'is' = 4 ticks 'invalid cast' = 147990 ticks Note this was just enough test to validate my assumption and that I never condone my developers taking an optimize first development approach... But there is still a right and a wrong way to do the job sometimes and exception driven development is not the right way. |
|
it doesn't matter, it's throwing an exception when the caller code is broken. That's ok, it's an error.