Type.IsArray Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mendapatkan nilai yang menunjukkan apakah jenisnya adalah array.
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
Nilai Properti
true jika jenis saat ini adalah array; jika tidak, false.
Penerapan
Contoh
Contoh berikut menunjukkan menggunakan IsArray properti .
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
Keterangan
Properti IsArray mengembalikan false untuk Array kelas . Ini juga mengembalikan jika instans false saat ini adalah Type objek yang mewakili jenis koleksi atau antarmuka yang dirancang untuk bekerja dengan koleksi, seperti IEnumerable atau IEnumerable<T>.
Untuk memeriksa array, gunakan kode seperti:
typeof(Array).IsAssignableFrom(type)
GetType(Array).IsAssignableFrom(type)
Jika jenis saat ini mewakili jenis generik, atau parameter jenis dalam definisi jenis generik atau metode generik, properti ini selalu mengembalikan false.
Properti ini hanya dapat dibaca.