As long as the cast succeeds performance should be the same, if the cast fails, isinst is much faster than castclass (because castclass has to throw an exception, which is expensive).
Note that neither of these instructions look at the elements of the array, i.e. only the type of the array is considered, not its contents. Regards, Jeroen > -----Original Message----- > From: Moderated discussion of advanced .NET topics. > [mailto:[EMAIL PROTECTED]] On Behalf Of > Shawn A. Van Ness > Sent: Thursday, January 09, 2003 22:29 > To: [EMAIL PROTECTED] > Subject: [ADVANCED-DOTNET] Performance: castclass vs. isinst? > > > Which is faster? For arrays, do both castclass and isinst > have to walk the list of elements, checking each one? > > I find I never know when to write > > string[] foo = > (string[])arraylist.ToArray(typeof(string)); // castclass > vs > string[] foo = > arraylist.ToArray(typeof(string)) as string[]; // isinst > > The latter is easer to type (fewer parens ;-) but seems to > give fits to VS's intellisense and auto-formatting features. :-( > > Cheers, > -Shawn > http://www.arithex.com/ > > You can read messages from the Advanced DOTNET archive, > unsubscribe from Advanced DOTNET, or > subscribe to other DevelopMentor lists at http://discuss.develop.com. > You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.