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

Can mvc be used for desktop applications?

477


How do you declare an arraylist?

487


How many bytes is a char c#?

479


What is the use of console?

479


Can we inherit static class in c#?

476






Explain the types of comments in c#?

540


Difference between Value type & reference types ? and give the example in .Net?

516


What is “using” statement in c#?

467


What is form feed and carriage return?

469


What are data types examples?

484


So let's say I have an application that uses myapp.dll assembly, version 1.0.0.0. There is a security bug in that assembly, and I publish the patch, issuing it under name myapp.dll 1.1.0.0. How do I tell the client applications that are already installed to start using this new myapp.dll?

483


How many constructor can a class have?

461


What does readonly mean in c#?

528


What benefit do you get from using a primary interop assembly (pia)?

504


How to declares a two-dimensional array in C#?

561