Developer community
0 votes
298 views
asked by Guru (24.6k points) 29 51 78 | 298 views

1 Answer

0 votes
Typeof is operator which applied to a object returns System.Type object. Typeof cannot be overloaded white GetType has lot of overloads.GetType is a method which also returns System.Type of an object. GetType is used to get the runtime type of the object. Example from MSDN showing Gettype used to retrive type at untime:-
public class MyBaseClass: Object {
}
public class MyDerivedClass: MyBaseClass {
}
public class Test {
public static void Main() {
MyBaseClass myBase = new MyBaseClass();
MyDerivedClass myDerived = new MyDerivedClass();
object o = myDerived;
MyBaseClass b = myDerived;
Console.WriteLine("mybase: Type is {0}", myBase.GetType());
Console.WriteLine("myDerived: Type is {0}", myDerived.GetType());
Console.WriteLine("object o = myDerived: Type is {0}", o.GetType());
Console.WriteLine("MyBaseClass b = myDerived: Type is {0}",
b.GetType());
}
}
answered by Expert (11.4k points) 14 22 29

Related questions

0 votes
1 answer
asked by sara Guru (24.6k points) 29 51 78 | 25 views
0 votes
1 answer
asked by rock Expert (15k points) 15 23 31 | 7 views
0 votes
1 answer
asked by felin Advisor (8.4k points) 10 15 18 | 20 views
0 votes
1 answer
asked by rock Expert (15k points) 15 23 31 | 18 views
0 votes
1 answer
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

Categories


C Books Guide and List
C++ Books Guide and List
Best Java Books

3.8k questions

4k answers

117 comments

10.7k users

3,751 questions
4,046 answers
117 comments
10,709 users