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
Name which controls do not have events?
What is static noise?
Can you see a loop recorder?
What is a service layer c#?
What is the difference between do and while loop?
Explain about generics in c#.net?
What are c# i/o classes? What are the commonly used i/o classes?
Can we customize the serialization process?
What are fields in c#?
Explain use of abstract and sealed classes in c#?
What are the differences between value types and reference types?
Why is .net so popular?
Explain boxing and unboxing in c#?
Why are c# strings immutable?
What does assert() do in c#?