Skip to content

Instantly share code, notes, and snippets.

@rtipton
Created March 19, 2010 19:00
Show Gist options
  • Save rtipton/338048 to your computer and use it in GitHub Desktop.
Save rtipton/338048 to your computer and use it in GitHub Desktop.
GetProperties()
using System;
using System.Reflection;
class Program
{
static void Main(string[] args)
{
var person = new Person
{ Name = "Rhonda",
FaveShow = "Fringe, Lost",
FaveMovie = "Star Trek",
FaveSong = "Contagious" };
var type = typeof(Person);
var properties = type.GetProperties();
foreach (PropertyInfo property in properties)
{
Console.WriteLine("{0} : {1}", property.Name, property.GetValue(person, null));
}
Console.Read();
}
}
public class Person
{
public string Name { get; set; }
public string FaveShow { get; set; }
public string FaveMovie { get; set; }
public string FaveSong { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment