I’ve seen both done in some code I’m maintaining, but don’t know the difference. Is there one?
let me add that myCustomer is an instance of Customer
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The result of both are exactly the same in your case. It will be your custom type that derives from
System.Type. The only real difference here is that when you want to obtain the type from an instance of your class, you useGetType. If you don’t have an instance, but you know the type name (and just need the actualSystem.Typeto inspect or compare to), you would usetypeof.Important difference
EDIT: Let me add that the call to
GetTypegets resolved at runtime, whiletypeofis resolved at compile time.