System.Type.GetElementType 方法

方法描述

当在派生类中重写时,返回当前数组、指针或引用类型包含的或引用的对象的 Type。

语法定义(C# System.Type.GetElementType 方法 的用法)

public abstract Type GetElementType()

参数/返回值

参数值/返回值 参数类型/返回类型 参数描述/返回描述
返回值 System.Type 当前数组、指针或引用类型包含或引用的对象的 Type;如果当前 Type 不是数组或指针,不是按引用传递,或者表示泛型类型或泛型方法的定义中的泛型类型或类型参数,则为 null。

提示和注释

对于 Array 类,此方法返回 null。

System.Type.GetElementType 方法例子

下面的示例说明如何使用 GetElementType 方法。

using System;
class TestGetElementType 
{
    public static void Main() 
    {
        int[] array = {1,2,3};
        Type t = array.GetType();
        Type t2 = t.GetElementType();
        Console.WriteLine("The element type of {0} is {1}.",array, t2.ToString());
        TestGetElementType newMe = new TestGetElementType();
        t = newMe.GetType();
        t2 = t.GetElementType();
        Console.WriteLine("The element type of {0} is {1}.", newMe, t2==null? "null" : t2.ToString());
    }
}

/* This code produces the following output:

The element type of System.Int32[] is System.Int32.
The element type of TestGetElementType is null.
 */

异常

异常 异常描述

命名空间

namespace: System

程序集: mscorlib(在 mscorlib.dll 中)

版本信息

.NET Framework 受以下版本支持:4、3.5、3.0、2.0、1.1、1.0 .NET Framework Client Profile 受以下版本支持:4、3.5 SP1 受以下版本支持:

适用平台

Windows 7, Windows Vista SP1 或更高版本, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008(不支持服务器核心), Windows Server 2008 R2(支持 SP1 或更高版本的服务器核心), Windows Server 2003 SP2 .NET Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求。