GetType() vs typeof() in C#

question-type-one-correct-icon‘typeof()’ is actually an operator for ‘GetType()’, so both function are same. Both returns an object ‘Type’ which can be used to find out further information like properties, methods and etc.

  1: Type typeObj = obj.GetType();  // Return the same result like typeof()
  2: Type typeObk = typeof(obj);    // Return the same result like .GetType()

0 comments:

Post a Comment