Adding properties dynamically to a class

后端 未结 6 1932
天命终不由人
天命终不由人 2020-12-03 17:14

In my class I have private variables and properties like this.

private string _itemCOde=string.Empty;
private string  _itemName=string.Empty;

public string          


        
6条回答
  •  借酒劲吻你
    2020-12-03 18:02

    You could use an ExpandoObject:

    Represents an object whose members can be dynamically added and removed at run time.

    dynamic expando = new ExpandoObject();
    expando.Cost= 42.0;
    expando.ItemName = "Shoes";
    

提交回复
热议问题