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
Does c# support const methods, properties, or events?
Explain About CLS?
If I return out of a try/finally in c#, does the code in the finally-clause run?
Give examples for reference types?
What are the Types of configuration files and their differences
Is arraylist thread safe?
We cannot create instances of static classes. Can we have constructors for static classes?
What is the default scope of a class in c#?
Can we inherit a class with private constructor in c#?
What is attribute and reflection in c#?
How can I make sure my c# classes will interoperate with other .net languages?
Write a console application and implement the ternary operator to decide whether the age a user entered after being prompted is allowed to vote or not(given that only citizens between 18 and 120 years only inclusive can vote). Use exception handling for non-numerical input.
Define sealed classes in c#?
List the fundamental oop concepts?
Expalin the way you implement inheritance by using VB.NET/C#?