Type.IsArray Właściwość

Definicja

Pobiera wartość, która wskazuje, czy typ jest tablicą.

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

Wartość właściwości

Boolean

true jeśli bieżący typ jest tablicą; w przeciwnym false razie .

Implementuje

Przykłady

W poniższym przykładzie pokazano użycie IsArray właściwości .

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

Uwagi

Właściwość IsArray zwraca wartość dla klasy false Array . Zwraca również wartość , jeśli bieżące wystąpienie jest obiektem reprezentującym typ kolekcji lub interfejs przeznaczony do pracy z false kolekcjami, takimi jak lub Type IEnumerable IEnumerable<T> .

Aby sprawdzić tablicę, użyj kodu takiego jak:

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

Jeśli bieżący typ reprezentuje typ ogólny lub parametr typu w definicji typu ogólnego lub metody ogólnej, ta właściwość zawsze zwraca wartość false .

Ta właściwość jest tylko do odczytu.

Dotyczy

Zobacz też