Type.IsArray 屬性

定義

取得值,以表示類型是否為陣列。Gets a value that indicates whether the type is an array.

public:
 virtual property bool IsArray { bool get(); };
public:
 property bool IsArray { bool get(); };
public virtual bool IsArray { get; }
public bool IsArray { get; }
member this.IsArray : bool
Public Overridable ReadOnly Property IsArray As Boolean
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 屬性會傳回 Array 類別的 falseThe IsArray property returns false for the Array class. 如果目前的實例是代表集合類型的 Type 物件,或是設計來處理集合的介面(例如 IEnumerableIEnumerable<T>),它也會傳回 falseIt 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.

適用於

另請參閱