_Type.HasElementType プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > _Type.HasElementType プロパティの意味・解説 

_Type.HasElementType プロパティ

メモ : このプロパティは、.NET Framework version 2.0新しく追加されたものです。

COM オブジェクトに、Type.HasElementType プロパティへのバージョン依存しないアクセス用意されています。

このプロパティは、CLS準拠していません。  

名前空間: System.Runtime.InteropServices
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Dim instance As _Type
Dim value As Boolean

value = instance.HasElementType
bool HasElementType { get; }
property bool HasElementType {
    bool get ();
}
/** @property */
boolean get_HasElementType ()
function get HasElementType () : boolean

プロパティ
Type配列ポインタであるか、参照渡しである場合trueそれ以外場合false

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Type.HasElementType プロパティ

現在の Type別の型を包含または参照しているかどうか、つまり現在の Type配列ポインタ、または参照渡しかどうかを示す値を取得します

名前空間: System
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Dim instance As Type
Dim value As Boolean

value = instance.HasElementType
public bool HasElementType { get;
 }
public:
virtual property bool HasElementType {
    bool get () sealed;
}
/** @property */
public final boolean get_HasElementType ()

プロパティ
Type配列ポインタであるか、参照渡しである場合trueそれ以外場合false

解説解説

たとえば、Type.GetType("Int32[]").HasElementType は true返しますが、Type.GetType("Int32").HasElementType は false返します。HasElementType は、"Int32*" と "Int32&" のどちらに対してtrue返します

現在の Typeジェネリック型、あるいはジェネリック型またはジェネリック メソッドの定義の型パラメータ表している場合、このプロパティは常に false返します

使用例使用例

オブジェクト配列参照型、またはポインタかどうかに応じてtrue または false返す例を次に示します

Imports System
Imports System.Reflection
Imports System.Runtime.InteropServices

Public Class Example

    ' This method is for demonstration purposes.
    Public Shared Sub Test(ByRef
 x As Integer, <Out> ByRef
 y As Integer)
    End Sub

    Public Shared Sub Main()
        ' All of the following display 'True'.

        ' Define an array, get its type, and display HasElementType.
 
        Dim nums() As Integer
 = {1, 1, 2, 3, 5, 8, 13}
        Dim t As Type = nums.GetType()
        Console.WriteLine("HasElementType is '{0}'
 for array types.", t.HasElementType)

        ' Test an array type without defining an array.
        t = GetType(Example())
        Console.WriteLine("HasElementType is '{0}'
 for array types.", t.HasElementType)

        ' When you use Reflection Emit to emit dynamic methods and
        ' assemblies, you can create array types using MakeArrayType.
        ' The following creates the type 'array of Example'.
        t = GetType(Example).MakeArrayType()
        Console.WriteLine("HasElementType is '{0}'
 for array types.", t.HasElementType)

        ' When you reflect over methods, HasElementType is true for
        ' ref, out, and pointer parameter types. The following 
        ' gets the Test method, defined above, and examines its
        ' parameters.
        Dim mi As MethodInfo = GetType(Example).GetMethod("Test")
        Dim parms() As ParameterInfo = mi.GetParameters()
        t = parms(0).ParameterType
        Console.WriteLine("HasElementType is '{0}'
 for ref parameter types.", t.HasElementType)
        t = parms(1).ParameterType
        Console.WriteLine("HasElementType is '{0}'
 for <Out> parameter types.", t.HasElementType)

        ' When you use Reflection Emit to emit dynamic methods and
        ' assemblies, you can create pointer and ByRef types to use
        ' when you define method parameters.
        t = GetType(Example).MakePointerType()
        Console.WriteLine("HasElementType is '{0}'
 for pointer types.", t.HasElementType)
        t = GetType(Example).MakeByRefType()
        Console.WriteLine("HasElementType is '{0}'
 for ByRef types.", t.HasElementType)
    End Sub 

End Class
// This code must be compiled with the /unsafe switch:
//   csc /unsafe source.cs
using System;
using System.Reflection;

public class Example
{
    // This method is for demonstration purposes.
    unsafe public void Test(ref int
 x, out int y, int* z) 
    { 
        *z = x = y = 0; 
    }

    public static void Main()
    {
        // All of the following display 'True'.

        // Define an array, get its type, and display HasElementType.
 
        int[] nums = {1, 1, 2, 3, 5, 8, 13};
        Type t = nums.GetType();
        Console.WriteLine("HasElementType is '{0}' for array
 types.", t.HasElementType);

        // Test an array type without defining an array.
        t = typeof(Example[]);
        Console.WriteLine("HasElementType is '{0}' for array
 types.", t.HasElementType);

        // When you use Reflection Emit to emit dynamic methods and
        // assemblies, you can create array types using MakeArrayType.
        // The following creates the type 'array of Example'.
        t = typeof(Example).MakeArrayType();
        Console.WriteLine("HasElementType is '{0}' for array
 types.", t.HasElementType);

        // When you reflect over methods, HasElementType is true for
        // ref, out, and pointer parameter types. The following 
        // gets the Test method, defined above, and examines its
        // parameters.
        MethodInfo mi = typeof(Example).GetMethod("Test");
        ParameterInfo[] parms = mi.GetParameters();
        t = parms[0].ParameterType;
        Console.WriteLine("HasElementType is '{0}' for ref
 parameter types.", t.HasElementType);
        t = parms[1].ParameterType;
        Console.WriteLine("HasElementType is '{0}' for out
 parameter types.", t.HasElementType);
        t = parms[2].ParameterType;
        Console.WriteLine("HasElementType is '{0}' for pointer
 parameter types.", t.HasElementType);

        // When you use Reflection Emit to emit dynamic methods and
        // assemblies, you can create pointer and ByRef types to use
        // when you define method parameters.
        t = typeof(Example).MakePointerType();
        Console.WriteLine("HasElementType is '{0}' for pointer
 types.", t.HasElementType);
        t = typeof(Example).MakeByRefType();
        Console.WriteLine("HasElementType is '{0}' for ByRef
 types.", t.HasElementType);
    }
}
using namespace System;
using namespace System::Reflection;
using namespace System::Runtime::InteropServices;

public ref class Example
{
public:
    // This method is for demonstration purposes. It includes a
    // tracking reference (C# ref, VB ByRef), an out parameter,
    // and a pointer.
    void Test(int% x, [OutAttribute()] int%
 y, int* z)
    { 
        *z = x = y = 0; 
    }    
};

int main()
{
    // All of the following display 'True'.

    // Define a managed array, get its type, and display HasElementType.
 
    array<Example^>^ examples = {gcnew Example(), gcnew Example()};
    Type^ t = examples::typeid; 
    Console::WriteLine(t);
    Console::WriteLine("HasElementType is '{0}' for managed
 array types.", t->HasElementType);

    // When you use Reflection Emit to emit dynamic methods and
    // assemblies, you can create array types using MakeArrayType.
    // The following creates the type 'array of Example'.
    t = Example::typeid->MakeArrayType();
    Console::WriteLine("HasElementType is '{0}' for managed
 array types.", t->HasElementType);

    // When you reflect over methods, HasElementType is true for
    // ref, out, and pointer parameter types. The following 
    // gets the Test method, defined above, and examines its
    // parameters.
    MethodInfo^ mi = Example::typeid->GetMethod("Test");
    array<ParameterInfo^>^ parms = mi->GetParameters();
    t = parms[0]->ParameterType;
    Console::WriteLine("HasElementType is '{0}' for ref parameter
 types.", t->HasElementType);
    t = parms[1]->ParameterType;
    Console::WriteLine("HasElementType is '{0}' for out parameter
 types.", t->HasElementType);
    t = parms[2]->ParameterType;
    Console::WriteLine("HasElementType is '{0}' for pointer
 parameter types.", t->HasElementType);

    // When you use Reflection Emit to emit dynamic methods and
    // assemblies, you can create pointer and ByRef types to use
    // when you define method parameters.
    t = Example::typeid->MakePointerType();
    Console::WriteLine("HasElementType is '{0}' for pointer
 types.", t->HasElementType);
    t = Example::typeid->MakeByRefType();
    Console::WriteLine("HasElementType is '{0}' for ByRef
 types.", t->HasElementType);
}
import System.*;

public class MyClass
{
} //MyClass

public class Type_HasElementType
{
    public static void main(String[]
 args)
    {
        try {
            // A nonarray, pointer, or reference element. 
            MyClass myObject1 = new MyClass();
            Object myObject2 = myObject1;

            // Define an array. 
            MyClass myObject3[] = new MyClass[5];
            Object myObject4 = myObject3;
            Object myObjects[] = new Object[] { myObject1, myObject2
,
                myObject3, myObject4 };
            Console.WriteLine("\nCheck whether the object is an array, "
                +"a pointer, or a reference type.\n");
            for (int i = 0; i < myObjects.get_Length();
 i++) {
                if (myObjects.get_Item(i).GetType().get_HasElementType())
 {
                    Console.WriteLine("myObject{0} is an array, pointer, or
 "
                        +"reference type.", System.Convert.ToString(i));
                }
                else {
                    Console.WriteLine("myObject{0} is not an array, pointer,
 " 
                        +"or reference type.", System.Convert.ToString(i));
                }
            }
        }
        catch (System.Exception e) {
            Console.WriteLine("Exception: {0} \n", e.get_Message());
        }
    } //main
} //Type_HasElementType
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
Type クラス
Type メンバ
System 名前空間
HasElementTypeImpl
IsArray
IsPointer
IsByRef
GetElementType
GetType


このページでは「.NET Framework クラス ライブラリ リファレンス」から_Type.HasElementType プロパティを検索した結果を表示しています。
Weblioに収録されているすべての辞書から_Type.HasElementType プロパティを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書から_Type.HasElementType プロパティを検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「_Type.HasElementType プロパティ」の関連用語

_Type.HasElementType プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



_Type.HasElementType プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS