Ler em inglês

Compartilhar via


Type.IsArray Propriedade

Definição

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

C#
public virtual bool IsArray { get; }
C#
public bool IsArray { get; }

Valor da propriedade

Boolean

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

Implementações

Exemplos

O exemplo a seguir demonstra como usar a IsArray propriedade.

C#
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

Comentários

A IsArray propriedade retorna false para a Array classe. Ele também retorna false se a instância atual é 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 um código como:

C#
typeof(Array).IsAssignableFrom(type)  

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

Esta propriedade é somente para leitura.

Aplica-se a

Produto Versões
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

Confira também