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 |
This is Kishore i am MCA graduate i have percentage less(52%) in my 10th still i completed .NET course any body tell me how to put fake experience with my BSC degree if you do not mind tell me some fake certificates giving consultencies names in Chennai,Bangalore
In a memory when you Box and Unbox a value-type what happens?
How to throw an caught exception from cath block?
You are designing a user control. You created new property called backgroundimage which is of type image. You wanted to disable storing this property in the user’s form. How to achieve this?
Why delegate is used in c#?
What is wpf application in c#?
How many digits are in an integer?
Which property of the textbox cannot be changed at runtime?
What is an assembly loader?
How To Maintain Transaction In C#?
1 Answers Phoenix Technologies,
What are bitwise logical operators?
how to retrieve binary data from database (using c#.net and sql server/windows application)