Advertisement
elena1234

Reflection - get and set property

May 30th, 2021
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.37 KB | None | 0 0
  1.  
  2.             var propertyName = personType.GetProperty("Name");
  3.             object nameValue = propertyName.GetValue(instance); // GetValue
  4.             Console.WriteLine(nameValue);
  5.  
  6.             propertyName.SetValue(instance, "Ivo Petrov"); // SetValue
  7.  
  8.             newNameValue = propertyName.GetValue(instance);
  9.             Console.WriteLine(nameValue);          
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement