Type.IsClass
property tells whether the type is a class or a delegate. How to distinguish between these two (class and delegate) using Type
class API?
Asked
Active
Viewed 87 times
1

czerny
- 15,090
- 14
- 68
- 96
-
If you need to check on a specific instance, [see this answer](https://stackoverflow.com/a/5819975). If you need to check on a specific _type_, [see this answer instead](https://stackoverflow.com/a/5819935). – Peter Duniho May 16 '20 at 22:53
-
@PeterDuniho Why was the question closed? I specifically asks about Type class API. The suggested already existing question https://stackoverflow.com/q/5819907/639687 doesn't mention the key trick `.IsSubclassOf(typeof(System.Delegate)))` shown in an answer below. Suggested already existing answer deals with checking on an instance rather than a Type. – czerny May 16 '20 at 23:27
-
1Please read my previous comment. The duplicate is simply one of many existing questions on SO that explain how to determine where a object's type lands within the type system, and I even provided a link in my comment to the answer that addresses your question _exactly_. For your edification, I've added several other questions which are also duplicates of this question. – Peter Duniho May 16 '20 at 23:30
-
This question is the more straight to the point and has the more explicit title. – v1nce Jul 12 '22 at 21:34
1 Answers
1
You can check if type is a subclass of System.Delegate
:
typeof(Foo).IsSubclassOf(typeof(System.Delegate)));

Sergey Berezovskiy
- 232,247
- 41
- 429
- 459