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


Please Help Members By Posting Answers For Below Questions

What is the task perform by clr?

571


What does return do in unity?

539


What is polymorphism c# example?

485


What is a reference type c#?

518


Define a strong name in .net?

544






Explain the difference between // comments, /* */ comments and /// comments?

499


What is hashtable in c# net with example?

472


What is typeof c#?

520


Why is dll used?

595


Explain jagged arrays in c#?

574


Which property do we set on a Combo Box to display data on it prior to setting the DataSource ?

538


What is reflection in c#?

496


What is difference between mutable and immutable in c#?

451


What is difference between array and arraylist c#?

462


What is a dictionary in c#?

498