What is the difference between myCustomer.GetType() and typeof(Customer) in C#?

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 use GetType. If you don’t have an instance, but you know the type name (and just need the actual System.Type to inspect or compare to), you would use typeof.

Important difference

EDIT: Let me add that the call to GetType gets resolved at runtime, while typeof is resolved at compile time.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)