it is advisable to pass many parameters [closed]

0

Cordial greeting. I am making an application in c # use the program in three layers but I have the doubt that if it is advisable to pass many parameters to a method, if not, what can I do? Is there a design pattern to solve this? example:

Public void Registrar(String Nombre, String Apellido, int Edad, 
                      Datetime fechaNacimiento,String Correo, 
                      String Direccion, char sexo){

}
    
asked by Diego Giraldo 30.03.2018 в 03:59
source

1 answer

0
// declaras una clase con tus parámetros
public class EnParametro
{
    public String Nombre  { get; set; }
    public String Apellido  { get; set; }
    public int Edad  { get; set; }
    public Datetime fechaNacimiento  { get; set; }
    public String Correo  { get; set; }
    public String Direccion  { get; set; }
    public char sexo  { get; set; }
}


// creas un método que usa la clase y asignas valores

public void cargar(){

EnParametro parametros = new EnParametro();
parametros.Nombre = "juan";

// envias los paramtros a tu metodo Registrar. y listoo.
Registrar(parametros);
}


public void Registrar(EnParametro parametros)
{
   string nombre = parametros.Nombre;
}
    
answered by 02.04.2018 / 23:33
source