What is the difference between TypeOf and GetType?
Answers were Sorted based on User's Feedback
Answer / brijen.patel
TypeOf and GetType Produce the same information but the
difference is where they get theis information from;
typeOf is used to get the type based on a class, that means
if you use typeOf with object, it will gives you error. you
must pass class as parameter. Whereas GetType is used to
get the type based on as object (an instance of a class)
means GetType needs parameter of object rather than class name.
| Is This Answer Correct ? | 18 Yes | 0 No |
GetType is a call that is made at runtime on an instance of
an object.
typeof() is resolved to a call at runtime, but loads the
type from the token
for the type. They probably resolve to the same call, it's
just that
GetType requires an instance. If I didn't need the instance,
I would use
typeof.
| Is This Answer Correct ? | 3 Yes | 0 No |
Answer / saurabh
TypeOf(): It is an operator, which used to find the type of known type at the time of compilation of the program. It depends on the class or type and cannot pass the object or instance of the class as a parameter to the TypeOf() operator.
GetType(): This is the method, using this method we can obtain the type of the object or the type of instance of the class. To call this method we need an object or an instance of a class.
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / avinash reddy r
typeOf is based on a class
Ex: Console.WriteLine(typeof(int))
O/P: System.Int32
GetType is based on a object
string s="Hello World"
Ex: Console.WriteLine(s.GetType())
| Is This Answer Correct ? | 1 Yes | 2 No |
Which language is used for desktop application?
In which situation(s), the use of "Delegate" is a good idea?
Is c# strongly typed?
What is event delegate in c#?
What is gac? How to put assembly in gac?
Is list passed by reference c#?
what is Anonymous Method.? and What is shadowing?
What is string interpolation in c#?
Define assert() method? How does it work?
How do I simulate optional parameters to com calls?
How do you declare an interface in c#?
What is an escape sequence? Name some string escape sequences in c#.
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)