First point is that the two strings are not with access modifiers, soon are private and will only be accessible within the class itself.
Taking advantage and changing the code, because it makes no sense for a class called nome
and two students inside it. The code should be like this:
public class Aluno
{
public string Nome {get;set;}
}
Now on the form
, you could instill your students. Example:
Aluno alunoA = new Aluno(){ Nome = "Aluno Exemplo A" };
Aluno alunoB = new Aluno(){ Nome = "Aluno Exemplo B" };
Finally, I could display the message:
MessageBox.Show(alunoA.nome,"Aluno");
This last section has to be within some method or event of the form
, a button click for example:
private void button1_Click(object sender, EventArgs e)
{
Aluno alunoA = new Aluno(){ Nome = "Aluno Exemplo A" };
Aluno alunoB = new Aluno(){ Nome = "Aluno Exemplo B" };
MessageBox.Show(alunoA.Nome+"\n"+ alunoB.Nome,"Alunos");
}
I liked this answer. The class should describe an entity, so
Aluno
, and entities have properties, soNome
.– Marcelo Shiniti Uchimura
Thank you very much, man. Your answer got me a lot of questions. Really worth!
– Rafael Ventura
@Rafaelventura if the question helped you, mark it as an answer. If you have questions, access the [Tour]
– Rovann Linhalis