How to send data to the constructor?

3

I need to help me understand the part of object programming.

I needed to pass a value that was not inside the test object to know the user's choice. But once again I am a beginner in objects.

How do I call in my main activity to receive the choice?

public class organizadist {

    public organizadist()
    {

    }

    public teste[] inicializa(teste[] objecto) {
// o que eu queria receber
if (escolha==1){
// faz alguma coisa 
}
if (escolha==2){


//faz outra coisa 



    }


    public static class teste {
        public int ola;


    }

}
    
asked by anonymous 08.07.2016 / 16:16

2 answers

0

Simple I learned this yesterday curiously.

In your activity:

 organizadist enviadados = new organizadist();
                organizadist.Teste array [] = enviadados.inicializa(listaClothes ,  escolha);

At your constructor: '

public teste[] inicializa(teste[] objecto , int escolha);
    
08.07.2016 / 16:28
0

You can do the following to pass value using constructor.

public FrmDetalheRet(string pstrAba, int pnuNuped, int pnuCdRetPedVda)
{
   InitializeComponent();

  if (pstrAba == strConstReceb)            
     //this.dgvReceb.Columns["colCdPRod"].Visible = false;            
  if (pstrAba == strConstPed)          
     // this.dgvReceb.Columns["col2"].Visible = false;           

  string strMsg = string.Empty;
  bool booRetorno = false;

  BLLDetItPedv bLLDetItPedv = new BLLDetItPedv();
  DataTable  dt = bLLDetItPedv.SelectDadosDetItPedvDAL(out strMsg, out    booRetorno, pnuNuped, pnuCdRetPedVda);

  if (!booRetorno)
  {
     MessageBoxHelper.WarningMessage(strMsg);
     return;
  }
  else
  {
     PopulaTabela(dt);
  }
}

// Na chamada da classe você passa os parâmetros necessários para o construtor:
FrmDetalheRet frmDetalheRet = new FrmDetalheRet(strConstPed,(int)dgvPedido["colNuPed", dgvPedido.CurrentRow.Index].Value,                    (int)dgvPedido["colCdRetPedVda", dgvPedido.CurrentRow.Index].Value);
frmDetalheRet.Show();

In the example above in the class I do some operations with the values that were passed as parameters.

    
08.07.2016 / 18:30