Freigeben über


Type.IsArray Eigenschaft

Definition

Ruft einen Wert ab, der angibt, ob der Typ ein Array ist.

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

Eigenschaftswert

truewenn der aktuelle Typ ein Array ist; andernfalls . false

Implementiert

Beispiele

Das folgende Beispiel veranschaulicht die Verwendung der IsArray Eigenschaft.

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
open System
open System.Collections

let types = 
    [ typeof<String>; typeof<int[]>
      typeof<ArrayList>; typeof<Array>
      typeof<ResizeArray<string>>
      typeof<seq<char>> ]
for t in types do
    printfn $"""{t.Name + ":",-15} IsArray = {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

Hinweise

Die IsArray Eigenschaft gibt für die Array Klasse zurückfalse. Es wird auch zurückgegeben false , wenn es sich bei der aktuellen Instanz um ein Type Objekt handelt, das einen Auflistungstyp oder eine Schnittstelle darstellt, die für die Arbeit mit Auflistungen wie IEnumerable z. B. oder IEnumerable<T>.

Um nach einem Array zu suchen, verwenden Sie Code wie:

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

Wenn der aktuelle Typ einen generischen Typ oder einen Typparameter in der Definition eines generischen Typs oder einer generischen Methode darstellt, gibt diese Eigenschaft immer zurück false.

Diese Eigenschaft ist schreibgeschützt.

Gilt für:

Weitere Informationen