How to send data to the constructor?

Asked

Viewed 37 times

3

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

I needed to pass a value that was not inside the test object to know what was the choice of the utility. But once again I’m a beginner in objects.

As I have to 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;


    }

}

2 answers

0

Simple learned it yesterday curiously.

In his activity :

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

In your constructor:`

public teste[] inicializa(teste[] objecto , int escolha);
  • I don’t think it’s working for the tests I did here later I’ll come back with more info

0

You can do as follows 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.

  • Thank you Lucas Queiroz Ribeiro, I’m getting the way how to post code format.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.