How can you loop over the properties of a class?

后端 未结 11 1575
温柔的废话
温柔的废话 2020-11-29 23:37

Is there a way in c# to loop over the properties of a class?

Basically I have a class that contains a large number of property\'s (it basically holds the results of

11条回答
  •  清歌不尽
    2020-11-30 00:19

    Use something like

    StringBuilder csv = String.Empty;
    PropertyInfo[] ps this.GetType().GetProperties();
    foreach (PropertyInfo p in ps)
    {
        csv.Append(p.GetValue(this, null);
        csv.Append(",");
    }
    

提交回复
热议问题