Dynamically add properties to a existing object

后端 未结 7 1285
说谎
说谎 2020-12-01 13:49

I create the person object like this.

 Person person=new Person(\"Sam\",\"Lewis\") 

It has properties like this.

person.Dob         


        
相关标签:
7条回答
  • 2020-12-01 14:25

    Take a look at the ExpandoObject.

    For example:

    dynamic person = new ExpandoObject();
    person.Name = "Mr bar";
    person.Sex = "No Thanks";
    person.Age = 123;
    

    Additional reading here.

    0 讨论(0)
提交回复
热议问题