首页 > 编程技术 > csharp

在c#中把字符串转为变量名并获取变量值的小例子

发布时间:2020-6-25 11:40

复制代码 代码如下:

public class Program
    {
        public string str = "spp";
        public string spp = "Hello World!";

        public static void Main(string[] args)
        {
            Program p = new Program();

            Console.WriteLine(p.GetType().GetField(p.str).GetValue(p).ToString());
            Console.ReadKey();
        }
    }

标签:[!--infotagslink--]

您可能感兴趣的文章: