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
What is difference between web and window application?
Does c# support #define for defining global constants?
What are c# types?
Is python easier than c#?
What is check/uncheck?
How long does it take to get a loop recorder put in?
Why does dllimport not work for me?
What is the difference between C# 3.5 and C# 4.0?
What is a struct in C#?
What is event delegate in c#?
What are static and dynamic variables?
Differentiate between method overriding from method overloading with its functionality?
What is the difference between Decorator and Adapter pattern?
1. Describe page life cycle?
What is the purpose of a console table?