We have to understand what each particle of a method declaration means:
encapsulamento tipo_de_retorno nome_do_metodo(parâmetros)
Explaining each field:
Encapsulation: You say where this method can be accessed, for this you have public
, private
, protected
, internal
.
In the case of public
is accessible by any scope;
In the case of private
is accessible only within the scope of the class in which it was declared;
In the case of protected
is accessible only within the scope of the class in which it was declared and its daughter classes;
In the case of internal
it is accessible only by members belonging to the same Assembly package.
Return type is the type your method will return, it can be any object or primitive type, be bool
, string
, int
, MeuObjeto
, etc..
This is the one that defines that will be returned by the keyword return
.
Method_name is the term you used to designate the method to be called.
Parameters are the parameters that this method will receive and work within it
An example would be:
public int soma(int a,int b)
{
return a+b;
}
The previous method can be accessed by any part of the code and its return will be a int
which represents the sum of parameters a and b.
Until now to create functions in c# it was rare to use if you have created several codes I imagine you should know the difference between a
void
and abool
right? It depends on what your method will return... a method called "veriricar" seems good to me to return a bool, according to the validation being true or talking about private and public, I think you already have an answer about this: https://answall.com/questions/23/qual-%C3%A9-a-difference%C3%A7a-between-modifiers-public-default-protected-e-private– Ricardo Pontual