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 purpose of a console table?
How can I develop an application that automatically updates itself from the web?
What is a linked list c#?
What is callback delegate in c#?
Can struct inherit from class c#?
Which is better javascript or c#?
The int maps to which C# keyword in .NET type?
2. What happened when BO object has been called?
What is the difference between as and is operators in c#?
Define a partial class?
Classes and structs can be declared as static, is this statement true or false?
Why do we need static class in c#?
What is interpolation in programming?
Can derived classes have greater accessibility than their base types?
What are the properties of a string class?