Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Definition of Type in .NET

Tags:

c#

.net

vb.net

This question gives me curiosity... When you want to define a type you must say GetType(Type) ex.: GetType(string), but ain't String a type itself?

Why do you need to use GetType in those situations? And, if the reason is because it is expecting a Type 'Type'... why isn't the conversion implicit... I mean, all the data is there...

like image 812
PedroC88 Avatar asked Nov 23 '25 09:11

PedroC88


1 Answers

What you're doing is getting a reference to the meta-data of the type ... it might be a little more obvious if you look at the C# version of the API, which is typeof(string) ... which returns a Type object with information about the string type.

You would generally do this when using reflection or other meta-programming techniques

like image 67
Joel Martinez Avatar answered Nov 24 '25 21:11

Joel Martinez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!