0 Replies - 1532 Views - Last Post: 11 May 2012 - 07:20 AM

#1 raoz  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 11-May 12

Field names of an object

Posted 11 May 2012 - 07:20 AM

Description: You need System.Text and System.Reflections;
You just pass in a instance of the object and it returns an array of strings of the names of the fields of the object.

using System.Text;
using System.Result;

input instance of object
return array of field name stringsGives you all the names of public fields of the object.

static string[] listmembers(Object obj)
{
    List<string> result = new List<string>();
    FieldInfo[] fields = obj.GetType().GetFields();
    foreach (FieldInfo field in fields)
    {
        result.Add(field.Name);
    }
    return result.ToArray();
}


Is This A Good Question/Topic? 0
  • +

Page 1 of 1