Type.IsArray 属性
获取一个值,通过该值指示 Type 是否为数组。
**命名空间:**System
**程序集:**mscorlib(在 mscorlib.dll 中)
语法
声明
Public ReadOnly Property IsArray As Boolean
用法
Dim instance As Type
Dim value As Boolean
value = instance.IsArray
public bool IsArray { get; }
public:
virtual property bool IsArray {
bool get () sealed;
}
/** @property */
public final boolean get_IsArray ()
public final function get IsArray () : boolean
属性值
如果 Type 是数组,则为 true;否则为 false。
备注
对于 Array 类,IsArray 属性 (Property) 返回 false。
要检查数组,请使用诸如 typeof(Array).IsAssignableFrom(type)
之类的代码。
如果当前 Type 表示泛型类型,或泛型类型或泛型方法的定义中的类型参数,则此属性始终返回 false。
此属性为只读。
示例
下面的示例演示如何使用 IsArray 属性 (Property)。
Imports System
Class TestIsArray
Public Shared Sub Main()
Dim array As Integer() = {1, 2, 3, 4}
Dim at As Type = GetType(Array)
Dim t As Type = array.GetType()
Console.WriteLine("The type is {0}. Is this type an array? {1}", at, at.IsArray)
Console.WriteLine("The type is {0}. Is this type an array? {1}", t, t.IsArray)
End Sub 'Main
End Class 'TestType
using System;
class TestIsArray
{
public static void Main()
{
int [] array = {1,2,3,4};
Type at = typeof(Array);
Type t = array.GetType();
Console.WriteLine("The type is {0}. Is this type an array? {1}", at, at.IsArray);
Console.WriteLine("The type is {0}. Is this type an array? {1}", t, t.IsArray);
}
}
using namespace System;
int main()
{
array<Int32>^array = {1,2,3,4};
Type^ at = Array::typeid;
Type^ t = array->GetType();
Console::WriteLine( "The type is {0}. Is this type an array? {1}", at, at->IsArray.ToString() );
Console::WriteLine( "The type is {0}. Is this type an array? {1}", t, t->IsArray.ToString() );
}
import System.*;
class TestIsArray
{
public static void main(String[] args)
{
int array[] = { 1, 2, 3, 4 };
Type at = Array.class.ToType();
Type t = array.GetType();
Console.WriteLine("The type is {0}. Is this type an array? {1}",
System.Convert.ToString(at),
System.Convert.ToString(at.get_IsArray()));
Console.WriteLine("The type is {0}. Is this type an array? {1}",
System.Convert.ToString(t),
System.Convert.ToString(t.get_IsArray()));
} //main
} //TestIsArray
这段代码产生以下输出:
Type is System.Array. IsArray? False
Type is System.Int32[]. IsArray? True
平台
Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
.NET Compact Framework
受以下版本支持:2.0、1.0