What is the difference between TypeOf, GetType and what are
the uses of TypeOf, GetType.
Answer Posted / konduru bhaskar raju
typeof and GetType produce the exact same information. But
the difference is where they get this 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 parameter.
Where GetType is used to get the type based on an object
(an instance of a class). Means GetType needs parameter of
object rather than class name.
You can understand more with example.
The following code will output “True”:
string instance = “”;
Type type1 = typeof(string);
Type type2 = instance.GetType();
Console.WriteLine(type1 == type2);
| Is This Answer Correct ? | 15 Yes | 5 No |
Post New Answer View All Answers
How many aware interfaces are there?
What I can do with c#?
Is comparator a functional interface?
What is thread pooling?
Define Final Class in C#
What is serialization in unity?
Which is faster dictionary or list?
What are cookies in c#?
What Is A Satellite Assembly?
What is #region in c#?
Explain About namespaces
What is the difference between “finalize” and “finally” methods in c#?
What is lazy loading c#?
What is xml document how do you open it?
Can a constructor be private in c#?