-1

I want to assign value to the property of the object of class. I have taken the list of property names using GetProperties();

      PropertyInfo [] props;
      props=typeof(Import_Column).GetProperties();

I have created an object

      Import_Column myobj=new Import_Column();

I want to do something like

      myobj.props[2]=value; //giving me error

How can i do it? is there any different approach?

Himanshu
  • 4,269
  • 16
  • 29
  • 37
ABS
  • 49
  • 1
  • 1
  • 9
  • 1
    try this http://stackoverflow.com/questions/619767/set-object-property-using-reflection – Vamsi May 29 '14 at 09:45

1 Answers1

0

You need to set the value to the property of the current object instance

string propertyName = "TheNameOfThePropertyToSet";
myobj.GetType().GetProperty(propertyName).SetValue(myobj, value, null);

or in your case you could use

myobj.GetType().GetProperty(props[2].Name).SetValue(myobj, value, null);
Steve
  • 208,592
  • 21
  • 221
  • 278