Created
March 19, 2010 19:00
-
-
Save rtipton/338048 to your computer and use it in GitHub Desktop.
GetProperties()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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