.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Home >> Code Snippets >> ADO.NET >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Difference between typeof and get type function

Posted By:Gowthammanju       Posted Date: June 30, 2011    Points: 40    Category: ADO.NET    URL: http://www.dotnetspark.com  

this code explain you about difference between typeof and get type function

here it is as

* 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.

 * 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.

string instance = "";

 Type type1 = typeof(string);

 Type type2 = instance.GetType();

 Console.WriteLine(type1 == type2);


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend