본문 바로가기
프로그래밍

C# 문자열로 변수이름 가져오기

by 어부 2020. 4. 19.
public class MyClass
{
    public string _datafile;

    public MyClass()
    {
        _datafile = "Hello";
    }

    public void PrintField()
    {
        var result = this.GetType().GetField("_datafile").GetValue(this); 
        Console.WriteLine(result); // will print Hello
    }
}