Type.IsArray Propiedad
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Obtiene un valor que indica si el tipo es una 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
true
si el tipo actual es una matriz; en caso contrario, false
.
En el ejemplo siguiente se muestra el uso de la IsArray propiedad .
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
La IsArray propiedad devuelve false
para la Array clase . También devuelve false
si la instancia actual es un Type objeto que representa un tipo de colección o una interfaz diseñada para trabajar con colecciones, como IEnumerable o IEnumerable<T>.
Para comprobar si hay una matriz, use código como:
typeof(Array).IsAssignableFrom(type)
GetType(Array).IsAssignableFrom(type)
Si el tipo actual representa un tipo genérico o un parámetro de tipo en la definición de un tipo genérico o un método genérico, esta propiedad siempre devuelve false
.
Esta propiedad es de sólo lectura.
Producto | Versiones |
---|---|
.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, 8, 9 |
.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, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1 |
UWP | 10.0 |
Comentarios de .NET
.NET es un proyecto de código abierto. Seleccione un vínculo para proporcionar comentarios: