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 the task perform by clr?
What does return do in unity?
What is polymorphism c# example?
What is a reference type c#?
Define a strong name in .net?
Explain the difference between // comments, /* */ comments and /// comments?
What is hashtable in c# net with example?
What is typeof c#?
Why is dll used?
Explain jagged arrays in c#?
Which property do we set on a Combo Box to display data on it prior to setting the DataSource ?
What is reflection in c#?
What is difference between mutable and immutable in c#?
What is difference between array and arraylist c#?
What is a dictionary in c#?