反射的作用想必大家都知道了吧,少量属性的自动化操作手动添加几下当然是没有问题的,但是属性数量较多的时候敲起这些繁锁的代码可以困了,再说对扩展和维护性造成很多的不遍,以下代码中如不能直接使用请添加using System.Text;的引用。

要想对一个类型实例的属性或字段进行动态赋值或取值,首先得得到这个实例或类型的Type,微软已经为我们提供了足够多的方法。

首先建立一个测试的类

public class MyClass
{
    public int one { set; get; }
    public int two { set; get; }
    public int five { set; get; }
    public int three { set; get; }
    public int four { set; get; }
}

相关文章:

  • 2021-06-29
  • 2022-12-23
  • 2022-01-17
  • 2022-12-23
  • 2021-08-21
  • 2022-12-23
  • 2021-12-03
猜你喜欢
  • 2022-02-04
  • 2022-12-23
  • 2021-10-28
  • 2022-12-23
相关资源
相似解决方案