Type.IsArrayImpl 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
protected:
abstract bool IsArrayImpl();
protected abstract bool IsArrayImpl ();
abstract member IsArrayImpl : unit -> bool
Protected MustOverride Function IsArrayImpl () As Boolean
반환
true
이 배열이면 Type이고, 그렇지 않으면 false
입니다.
예제
다음 예제에서는 재정의 IsArrayImpl
합니다 메서드를 MyTypeDelegator
클래스, 변수가 배열 인지 확인 하 고 결과 표시 합니다.
using namespace System;
using namespace System::Reflection;
public ref class MyTypeDelegator: public TypeDelegator
{
public:
String^ myElementType;
Type^ myType;
MyTypeDelegator( Type^ myType )
: TypeDelegator( myType )
{
this->myType = myType;
}
protected:
// Override IsArrayImpl().
virtual bool IsArrayImpl() override
{
// Determine whether the type is an array.
if ( myType->IsArray )
{
myElementType = "array";
return true;
}
// Return false if the type is not an array.
return false;
}
};
int main()
{
try
{
int myInt = 0;
// Create an instance of an array element.
array<Int32>^myArray = gcnew array<Int32>(5);
MyTypeDelegator^ myType = gcnew MyTypeDelegator( myArray->GetType() );
Console::WriteLine( "\nDetermine whether the variable is an array.\n" );
// Determine whether myType is an array type.
if ( myType->IsArray )
Console::WriteLine( "The type of myArray is {0}.", myType->myElementType );
else
Console::WriteLine( "myArray is not an array." );
myType = gcnew MyTypeDelegator( myInt.GetType() );
// Determine whether myType is an array type.
if ( myType->IsArray )
Console::WriteLine( "The type of myInt is {0}.", myType->myElementType );
else
Console::WriteLine( "myInt is not an array." );
}
catch ( Exception^ e )
{
Console::WriteLine( "Exception: {0}", e->Message );
}
}
using System;
using System.Reflection;
public class MyTypeDelegator : TypeDelegator
{
public string myElementType = null;
public Type myType;
public MyTypeDelegator(Type myType) : base(myType)
{
this.myType = myType;
}
// Override IsArrayImpl().
protected override bool IsArrayImpl()
{
// Determine whether the type is an array.
if(myType.IsArray)
{
myElementType = "array";
return true;
}
// Return false if the type is not an array.
return false;
}
}
public class Type_IsArrayImpl
{
public static void Main()
{
try
{
int myInt = 0 ;
// Create an instance of an array element.
int[] myArray = new int[5];
MyTypeDelegator myType = new MyTypeDelegator(myArray.GetType());
Console.WriteLine("\nDetermine whether the variable is an array.\n");
// Determine whether myType is an array type.
if( myType.IsArray)
Console.WriteLine("The type of myArray is {0}.", myType.myElementType);
else
Console.WriteLine("myArray is not an array.");
myType = new MyTypeDelegator(myInt.GetType());
// Determine whether myType is an array type.
if( myType.IsArray)
Console.WriteLine("The type of myInt is {0}.", myType.myElementType);
else
Console.WriteLine("myInt is not an array.");
}
catch( Exception e )
{
Console.WriteLine("Exception: {0}", e.Message );
}
}
}
open System.Reflection
type MyTypeDelegator(myType) =
inherit TypeDelegator(myType)
[<DefaultValue>]
val mutable public myElementType : string
// Override IsArrayImpl().
override this.IsArrayImpl() =
// Determine whether the type is an array.
if myType.IsArray then
this.myElementType <- "array"
true
// Return false if the type is not an array.
else false
try
let myInt = 0
// Create an instance of an array element.
let myArray = Array.zeroCreate<int> 5
let myType = MyTypeDelegator(myArray.GetType())
printfn "\nDetermine whether the variable is an array.\n"
// Determine whether myType is an array type.
if myType.IsArray then
printfn $"The type of myArray is {myType.myElementType}."
else
printfn "myArray is not an array."
let myType = MyTypeDelegator(myInt.GetType())
// Determine whether myType is an array type.
if myType.IsArray then
printfn $"The type of myInt is {myType.myElementType}."
else
printfn "myInt is not an array."
with e ->
printfn $"Exception: {e.Message}"
Imports System.Reflection
Public Class MyTypeDelegator
Inherits TypeDelegator
Public myElementType As String = Nothing
Public myType As Type
Public Sub New(ByVal myType As Type)
MyBase.New(myType)
Me.myType = myType
End Sub
' Override IsArrayImpl().
Protected Overrides Function IsArrayImpl() As Boolean
' Determine whether the type is an array.
If myType.IsArray Then
myElementType = "array"
Return True
End If
' Return false if the type is not an array.
Return False
End Function 'IsArrayImpl
End Class
Public Class Type_IsArrayImpl
Public Shared Sub Main()
Try
Dim myInt As Integer = 0
' Create an instance of an array element.
Dim myArray(4) As Integer
Dim myType As New MyTypeDelegator(myArray.GetType())
Console.WriteLine(ControlChars.NewLine + "Determine whether the variable is an array." + ControlChars.NewLine)
' Determine whether 'myType' is an array type.
If myType.IsArray Then
Console.WriteLine("The type of myArray is {0}.", myType.myElementType)
Else
Console.WriteLine("myArray is not an array.")
End If
myType = New MyTypeDelegator(myInt.GetType())
' Determine whether myType is an array type.
If myType.IsArray Then
Console.WriteLine("The type of myInt is {0}.", myType.myElementType)
Else
Console.WriteLine("myInt is not an array.")
End If
Catch e As Exception
Console.WriteLine("Exception: {0}", e.Message.ToString())
End Try
End Sub
End Class
설명
클래스의 instance 배열이 Array 아닌 개체이므로 를 반환 false
해야 합니다.
적용 대상
추가 정보
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET