4
Pupil:
public class Aluno{ public int Id { get; set; } public string Nome { get; set; } public string Sobrenome { get; set; } }
Now I need to access the student’s Name and Surname through a string, how can I do this?
EX.:
string opcaoA = "Nome"; var resultado = Aluno + ".opcaoA "; //Resultado = "João";
I think it’s impossible! Object attributes and strings are not equivalent. C# is not javascript.
– Michael Pacheco
@Michaelpacheco This is possible and is very common. It is called Reflection.
– Jéf Bueno
@jbueno Very interesting!
– Michael Pacheco