class Program{ static void Main(string[] args){ User user = new User(); Type type = user.GetType(); PropertyInfo prop = type.GetProperty("Name"); prop.SetValue(user, "Bangalore", null); System.Console.WriteLine(user.Name); Console.ReadLine(); } } class User{ public int Id { get; set; } public string Name { get; set; } }
Bangalore
以上就是如何在C#中通过反射设置属性值?的详细内容,更多请关注php中文网其它相关文章!
已抢65567个
抢已抢30276个
抢已抢16652个
抢已抢8443个
抢已抢10924个
抢已抢22303个
抢