how to get value from object in csharp

Code Example - how to get value from object in csharp

                
                        var nameOfProperty = "property1";
var propertyInfo = myObject.GetType().GetProperty(nameOfProperty);
var value = propertyInfo.GetValue(myObject, null);