Type
.
Type
is a large
class with many members, and a discussion is deferred until the next section, where reflection
is examined. However, to briefly demonstrate
Type
, the following program uses three of
its properties:
FullName
,
IsClass
, and
IsAbstract
. To obtain the full name of the type, use
FullName
.
IsClass
returns true if the type is a class.
IsAbstract
returns true if a class is abstract.
// Demonstrate typeof.
using System;
using System.IO;
class UseTypeof {
static void Main() {
Type t = typeof(StreamReader);
Console.WriteLine(t.FullName);
if(t.IsClass) Console.WriteLine("Is a class.");
if(t.IsAbstract) Console.WriteLine("Is abstract.");
else Console.WriteLine("Is concrete.");
}
}
This program outputs the following:
System.IO.StreamReader
Is a class.
Is concrete.
www.freepdf-books.com
Do'stlaringiz bilan baham: |