Type.IsArray Type.IsArray Type.IsArray Type.IsArray Property

定义

获取一个值,该值指示类型是否为数组。Gets a value that indicates whether the type is an array.

public:
 property bool IsArray { bool get(); };
public bool IsArray { get; }
member this.IsArray : bool
Public ReadOnly Property IsArray As Boolean

属性值

如果当前类型是数组,则为 true;否则为 falsetrue if the current type is an array; otherwise, false.

实现

示例

下面的示例演示了如何使用IsArray属性。The following example demonstrates using the IsArray property.

using System;
using System.Collections;
using System.Collections.Generic;

public class Example
{
   public static void Main()
   {
      Type[] types = { typeof(String), typeof(int[]),
                       typeof(ArrayList), typeof(Array),
                       typeof(List<String>),
                       typeof(IEnumerable<Char>) };
      foreach (var t in types)
         Console.WriteLine("{0,-15} IsArray = {1}", t.Name + ":",
                           t.IsArray);
   }
}
// The example displays the following output:
//       String:         IsArray = False
//       Int32[]:        IsArray = True
//       ArrayList:      IsArray = False
//       Array:          IsArray = False
//       List`1:         IsArray = False
//       IEnumerable`1:  IsArray = False
Imports System.Collections
Imports System.Collections.Generic

Module Example
   Public Sub Main()
      Dim types() As Type = { GetType(String), GetType(Integer()),
                              GetType(ArrayList), GetType(Array),
                              GetType(List(Of String)),
                              GetType(IEnumerable(Of Char)) }
      For Each t In types
         Console.WriteLine("{0,-15} IsArray = {1}", t.Name + ":", t.IsArray)
      Next
   End Sub
End Module
' The example displays the following output:
'       String:         IsArray = False
'       Int32[]:        IsArray = True
'       ArrayList:      IsArray = False
'       Array:          IsArray = False
'       List`1:         IsArray = False
'       IEnumerable`1:  IsArray = False

注解

IsArray属性返回falseArray类。The IsArray property returns false for the Array class. 它还会返回false当前实例是否Type对象,表示集合类型或接口,可使用集合,如IEnumerableIEnumerable<T>It also returns false if the current instance is a Type object that represents a collection type or an interface designed to work with collections, such as IEnumerable or IEnumerable<T>.

若要检查的数组,请使用代码,如所示:To check for an array, use code such as:

typeof(Array).IsAssignableFrom(type)  
GetType(Array).IsAssignableFrom(type)  

如果当前类型表示泛型类型或泛型类型或泛型方法定义中的类型参数,此属性始终返回falseIf the current type represents a generic type, or a type parameter in the definition of a generic type or generic method, this property always returns false.

此属性是只读的。This property is read-only.

适用于

另请参阅