using System; using System.Reflection; public class Person { public string FirstName { get; set; } public string LastName { get; set; } public int Age { get; set; } } class Program { static void Main(string[] args) { Type type = typeof(Person); PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance); foreach (PropertyInfo property in properties) { Console.WriteLine($"Name: {property.Name}\nType: {property.PropertyType}\n"); } } }
using System; using System.Reflection; public class Person { public string FirstName { get; set; } public string LastName { get; set; } public int Age { get; set; } } class Program { static void Main(string[] args) { Person person = new Person { FirstName = "John", LastName = "Doe", Age = 25 }; Type type = person.GetType(); PropertyInfo property = type.GetProperty("Age"); int age = (int)property.GetValue(person); Console.WriteLine($"Age: {age}"); } }In this example, we create a Person object, set its properties to initial values, and retrieve its type at runtime. We then use the GetProperty method to retrieve the Age property and the GetValue method to get the value of the property. Finally, we print out the age value. We can conclude that both examples use the System.Reflection package library.