Partilhar via


Type.IsArray Propriedade

Definição

Obtém um valor que indica se o tipo é uma matriz.

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

Valor da propriedade

true se o tipo atual for uma matriz; caso contrário, false.

Implementações

Exemplos

O exemplo a seguir demonstra o uso da IsArray propriedade.

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

Comentários

A IsArray propriedade retorna false para a Array classe. Ele também retornará false se a instância atual for um Type objeto que representa um tipo de coleção ou uma interface projetada para trabalhar com coleções, como IEnumerable ou IEnumerable<T>.

Para verificar se há uma matriz, use código como:

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

Se o tipo atual representar um tipo genérico ou um parâmetro de tipo na definição de um tipo genérico ou método genérico, essa propriedade sempre retornará false.

Esta propriedade é somente para leitura.

Aplica-se a

Confira também