How to iterate on all properties of an object in C#?

后端 未结 3 1373
时光说笑
时光说笑 2021-02-08 16:22

I am new to C#, I want to write a function to iterate over properties of an object and set all null strings to \"\". I have heard that it is possible using something called \"Re

3条回答
  •  长情又很酷
    2021-02-08 17:15

    object myObject;
    
    PropertyInfo[] properties = myObject.GetType().GetProperties(BindingFlags.Instance);
    

    See http://msdn.microsoft.com/en-us/library/aa332493(VS.71).aspx

提交回复
热议问题