美文网首页
反射的简单用法

反射的简单用法

作者: 价值投机168 | 来源:发表于2023-05-17 13:13 被阅读0次

{
class AAA
{
public string name;
}
class Program
{
static void Main(string[] args)
{
AAA a = new AAA();

        Type atype = typeof(AAA);
        Type bt = a.GetType();

        var cc = Activator.CreateInstance(bt);
        FieldInfo fi = bt.GetField("name");
        fi.SetValue(cc, "test");
        Console.WriteLine("Hello World!" + fi.GetValue(cc));
        Console.ReadLine();
    }
}

}

相关文章

网友评论

      本文标题:反射的简单用法

      本文链接:https://www.haomeiwen.com/subject/fmsisdtx.html