/ Published in: C#
Reflection is an important capability of the .NET framework and enables you to get information about objects at runtime. In this snippet, we will iterate through all properties for a class named Person using reflection.
The Person class extends System.Object and does not implement any interface. It is a simple class used to store information about a person.
Expand |
Embed | Plain Text
using System; class Program { static void Main(string[] args) { 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 int Age { get; set; } public string Name { get; set; } }
You need to login to post a comment.
