다음을 통해 공유


FieldInfo.FieldType 속성

정의

이 필드 개체의 형식을 가져옵니다.

public:
 abstract property Type ^ FieldType { Type ^ get(); };
public abstract Type FieldType { get; }
member this.FieldType : Type
Public MustOverride ReadOnly Property FieldType As Type

속성 값

이 필드 개체의 형식입니다.

구현

예제

다음 예제에서는 필드를 만들고, 해당 형식 및 을 FieldInfo가져오고, 해당 를 FieldType표시합니다.

using System;
using System.Reflection;

public class TestClass
{
    // Define a field.
    private string field = "private field";
}

public class Example
{
    public static void Main()
    {
        var cl= new TestClass();

        // Get the type and FieldInfo.
        Type t = cl.GetType();
        FieldInfo fi = t.GetField("field",
            BindingFlags.Instance | BindingFlags.NonPublic);

        // Get and display the field type.
        Console.WriteLine("Field Name: {0}.{1}", t.FullName, fi.Name);
        Console.WriteLine("Field Value: '{0}'", fi.GetValue(cl));
        Console.WriteLine("Field Type: {0}", fi.FieldType);
    }
}
// The example displays the following output:
//       Field Name: TestClass.field
//       Field Value: 'private field'
//       Field Type: System.String
Imports System.Reflection

Public Class TestClass
    ' Define a field.
    Private field As String = "private field"
End Class

Public Module Example
    Public Sub Main()
        Dim cl As New TestClass()

        ' Get the type and FieldInfo.
        Dim t As Type = cl.GetType()
        Dim fi As FieldInfo = t.GetField("field", _
                 BindingFlags.Instance Or BindingFlags.NonPublic)

        ' Get and display the FieldType.
        Console.WriteLine("Field Name: {0}.{1}", t.FullName, fi.Name)
        Console.WriteLine("Field Value: '{0}'", fi.GetValue(cl))
        Console.WriteLine("Field Type: {0}", fi.FieldType)
    End Sub 
End Module
' The example displays the following output:
'       Field Name: TestClass.field
'       Field Value: 'private field'
'       Field Type: System.String

설명

형식은 , Boolean또는 GUID와 같은 String일부 기본 데이터 형식입니다.

속성을 얻으려면 FieldType 먼저 클래스 Type를 가져옵니다. 에서 를 Type가져옵니다 FieldInfo. FieldInfo에서 값을 가져옵니다FieldType.

적용 대상

추가 정보