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
Can mvc be used for desktop applications?
How do you declare an arraylist?
How many bytes is a char c#?
What is the use of console?
Can we inherit static class in c#?
Explain the types of comments in c#?
Difference between Value type & reference types ? and give the example in .Net?
What is “using” statement in c#?
What is form feed and carriage return?
What are data types examples?
So let's say I have an application that uses myapp.dll assembly, version 1.0.0.0. There is a security bug in that assembly, and I publish the patch, issuing it under name myapp.dll 1.1.0.0. How do I tell the client applications that are already installed to start using this new myapp.dll?
How many constructor can a class have?
What does readonly mean in c#?
What benefit do you get from using a primary interop assembly (pia)?
How to declares a two-dimensional array in C#?