Here we see you can assign Type variables to the result of a typeof expression. And methods receive a Type parameter as an argument.
using System;
class Program
{
static void Main()
{
// Use type variables.
// ... Then pass the variables as an argument.
Type type1 = typeof(string[]);
Type type2 =
"string".GetType();
Type type3 = typeof(Type);
Test(type1);
Test(type2);
Test(type3);
}
static void Test(Type type)
{
// Print some properties of the Type formal parameter.
Console.WriteLine(
"IsArray: {0}", type.IsArray);
Console.WriteLine(
"Name: {0}", type.Name);
Console.WriteLine(
"IsSealed: {0}", type.IsSealed);
Console.WriteLine(
"BaseType.Name: {0}", type.BaseType.Name);
Console.WriteLine();
}
}
IsArray: True
Name: String[]
IsSealed: True
BaseType.Name: Array
IsArray: False
Name: String
IsSealed: True
BaseType.Name: Object
IsArray: False
Name: Type
IsSealed: False
BaseType.Name: MemberInfo