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 difference between list and dictionary in c#?
What does do in c#?
What is firstordefault c#?
Which is faster dictionary or hashtable?
Why singleton is sealed?
If I return out of a try/finally in c#, does the code in the finally-clause run?
Where test director stores its data ? Database ,Local file etc...? I need to read this data from Visual Studio 2005 c# client. Regards
What is Wrapper class in dot net?
What is icollection in c#?
I have 3 overloaded constructors in my class. In order to avoid making instance of the class do I need to make all constructors to private?
update data in an xml file which resides in solution itself, using silverlight 4.0
Why delegate is used in c#?
What is private void in c#?
What is the difference between abstract class and interface in c#?
What is a constructor in c#?