Posted By


rtipton on 02/28/10

Tagged


Statistics


Viewed 199 times
Favorited by 2 user(s)

GetProperties()


/ Published in: C#
Save to your folder(s)



Copy this code and paste it in your HTML
  1. using System;
  2. using System.Reflection;
  3.  
  4. class Program
  5. {
  6. static void Main(string[] args)
  7. {
  8. var person = new Person
  9. { Name = "Rhonda",
  10. FaveShow = "Fringe, Lost",
  11. FaveMovie = "Star Trek",
  12. FaveSong = "Contagious" };
  13.  
  14. var type = typeof(Person);
  15. var properties = type.GetProperties();
  16.  
  17. foreach (PropertyInfo property in properties)
  18. {
  19. Console.WriteLine("{0} : {1}", property.Name, property.GetValue(person, null));
  20. }
  21.  
  22. Console.Read();
  23. }
  24. }
  25.  
  26. public class Person
  27. {
  28. public string Name { get; set; }
  29. public string FaveShow { get; set; }
  30. public string FaveMovie { get; set; }
  31. public string FaveSong { get; set; }
  32. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.