1
To avoid having to manually type the data after an update to the objects, I decided to create a method of type static
to be accessed by passing the object as parameter.
public static void Relatorio(Trem trem)
{
Console.WriteLine($"{trem} - PESO ATUAL: {trem.getPesoVagao()}");
Console.WriteLine($"{trem} - PESO SUPORTADO: {trem.getCargaMAX()}");
Console.WriteLine($"{trem} - CARGA DISPONÍVEL: {trem.CargaRestante()}");
Console.WriteLine();
Console.WriteLine();
}
That would keep me from writing the report on Main()
whenever you make a change to the object, but the returned name that should be "T2" is returning as SobrecargaDeMetodos.Trem
.
I call the method as follows by passing the object to be analyzed as parameter. The part showing the result works perfectly, but the name does not.
Trem.Relatorio(T2);
I think this is a lot of gambit to solve the problem, a property has to be something that belongs to the object. Looking at the code without looking at the problem, I understand that this property stores the
Nome
of aTrem
.– Roberto de Campos
@Robertodecampos I do not understand the reason. In my view it may even be one of the best options to solve the problem. Unless it doesn’t make any sense that the trains have a name.
– Bruno Costa
So that’s the question, he doesn’t want to get the name of the train, but to get the name of the variable that stores the object
Trem
.– Roberto de Campos
@Robertodecampos But this concept does not even make sense, since the variables may have the identifiers I want. Once the variable can be called
trem
and other timest2
. I can also have several variables that point to the same object.– Bruno Costa
Exactly, it doesn’t make sense, but that’s exactly what @Ramonalmeida is asking! The question itself is probably already a gambit.
– Roberto de Campos
@Robertodecampos. I will leave my answer even, It continues to seem to me that it is a logical way to solve the problem, even if it is not "even to the letter" to the situation indicated by the AP.
– Bruno Costa