4
As far as I know Overload in the creation of methods, which are execution options, example(very simple), a method where you have the option to pass 2 or 3 parameters calling the same function:
//Soma 2 numeros
public int Somar(int a, int b)
{
return a + b;
}
//Soma 3 numeros
public int Somar(int a,int b, int c)
{
return a + b + c;
}
The question is: Can I create a return Overload? Like for example:
public PessoaJuridica RetornarPessoa(string id)
{
return new PessoaJuridica();
}
public PessoaFisica RetornarPessoa(string id)
{
return new PessoaFisica();
}
The need arose because I have two method with different names and it would be easier for me to use the same name because they do "the same thing".
how you separate natural person from legal person, I mean, in the database, are in separate tables ?
– Rovann Linhalis
Rovann, it was one example only, I am not using Personal and Personal, is that I have two types of user, the common User(who queries photos) and a user contributor(who sends), and I wanted to receive the profile data of both through a method name only and not two.
– Leonardo Bonetti
right, so, these two types of users, are on the same table ? there is a field that identifies which type it is ?
– Rovann Linhalis
They are in different tables, because in this case the information of each is different BEEEM. Let’s say it’s another area of the site, they have no relationship to each other.
– Leonardo Bonetti
in this case, I would go by Generics even, if I had an inheritance relationship, I could even use polymorphism, but if it has no relation, I would use an interface and generic method
– Rovann Linhalis