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
Is arraylist type safe in c#?
What is the use of main method in c#?
Does c# support #define for defining global constants?
What is asenumerable in c#?
Explain the role of the datareader class in ado.net connections?
Explain what are the steps for creating clr trigger?
How can I access the registry from c# code?
How do namespaces work?
Differentiate between the public and private ?
What's your approach to fetch static data in your windows form application?
Can an int be negative c#?
What are the applications of c#?
What is meant by enumerable in c#?
What are the variables in c#?
What is assembly version series sequence?