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.

適用於

另請參閱