title: Getting list of class fields
body: <p>I am trying to create a generic method for my search, but I don't know how to return list of fields from my class.</p>
  
  <p>Let's say I've got a class: </p>
  
  <pre><code>public class Table
      {
          [Key]
          public int ID { get; set; }
  
          public string Name { get; set; }
  
          public string Address { get; set; }
      }
  </code></pre>
  
  <p>And now I want to return a list that would look like this:</p>
  
  <pre><code>"ID"
  "Name"
  "Address"
  </code></pre>
  
  <p>How do I do that?</p>
  
  <p>tried something like this:</p>
  
  <pre><code> FieldInfo[] fields = typeof(T).GetFields(
              BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
              string[] names = Array.ConvertAll&lt;FieldInfo, string&gt;(fields,
                  delegate(FieldInfo field) { return field.Name; });
  </code></pre>
  
  <p>But it has some unnecessary text after field names</p>
  
  <h2><strong>EDIT</strong></h2>
  
  <p>It's not duplicate because in my situation GetProperties()<strong>.Select(f => f.Name)</strong> made a difference</p>