O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Discovering Types

Now that you know we can query lots of properties of types, we should briefly revisit how we can obtain the Type objects themselves. There are three main ways to do so, the first of which we’ve already covered: use of the typeof operator in C#. Although this way is the most direct, it has little value in scenarios where you’re really about to find out about type information you didn’t know about at compile time:

var stringType = typeof(string /* you did know the type name, didn't you? */);var intType = typeof(int /* same story here */);

Because every object floating around in the CLR’s managed memory space has a type, it’s obvious one should be able to obtain a System.Type instance from any object. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required