9
¿Cómo hago esto en C#?¿Cómo accedo a una propiedad de objeto con una variable de cadena que tiene el nombre de esa propiedad?
using System;
namespace TestProperties28373
{
class Program
{
static void Main(string[] args)
{
Customer customer = new Customer { FirstName = "Jim", LastName = "Smith", Age = 34};
Console.WriteLine(customer.FirstName);
string propertyName = "FirstName";
Console.WriteLine(customer.&&propertyName); //PSEUDO-CODE
Console.ReadLine();
}
}
class Customer
{
public string FirstName { get; set; }
public string LastName { get; set; }
public int Age { get; set; }
}
}