Re: Knowing an object implements an Interface

Tech-Archive recommends: Fix windows errors by optimizing your registry



Ron M. Newman wrote:
Hi,

Is there a quick way to know if a given object implements IComparable?
(without casting or anything like that). Something that uses
reflection?

casting under the CLR uses reflection (well, type meta-data, not the
relfection API per-se), so you're tilting against windmills trying to do it
"without casting or anything like that". Just use the 'is' operator in C#
(trycast in IL).

-cd


.



Relevant Pages

  • Re: Addition of two values
    ... aim by casting the input Object values /val1 and val2/ to certain Interfaces ... for example, or using reflection probably. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: What is better?
    ... They both use reflection which is slower than casting. ... What is better (faster/performance) when publishing inside an aspx ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Knowing an object implements an Interface
    ... Ron M. Newman wrote: ... (without casting or anything like that). ... Something that uses reflection? ...
    (microsoft.public.dotnet.languages.csharp)