Click here to Skip to main content
15,885,916 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
private void button1_Click(object sender, EventArgs e)
{
    Funcionario Func = new Funcionario(Func.getNome(),
                                       Func.getSexo(),
                                       Func.getDataNascimento(),
                                       Func.getBi(),
                                       Func.getTelefone(),
                                       Func.getMorada(),
                                       Func.getEmail());
}


in this code, im having this error : use of unassigned variable "Func", anyone knows how to put this right?

Thanks
Posted
Updated 14-Jan-13 13:59pm
v2
Comments
Jibesh 14-Jan-13 20:13pm    
what? !!! are you sure what you are going to do with that line.

we dont know your requirement, we dont know what your program does so its hard to tell with this much information, you need to elaborate your question. You can use the 'Improve Question' link to edit your question or to post more code.

Have a look at the solution it will help you to get going with the problem.
Garth J Lancaster 14-Jan-13 20:25pm    
ouch - I suspect the compiler is seeing 'Func.getNome() .... ' for example, but, at that stage, Func doesnt yet exist, becuase of the Funcionario Func = new Functionario ...

This all being said, I agree with jibesh .. what exactely are you trying to do, becuase Im not sure thats the way to go about it !

In this case the instance Func will be created/initialized only when the construction is done, but you are invoking a method of the instance Func before its construction through Fun.getName(),getSexo etc .

I am not sure what you are trying to do here. Looks like you are confused with the constructor overrides available in the 'Funcinario' class

It should be something like this

C#
private void button1_Click(object sender, EventArgs e)
{
    Funcionario Func = new Funcionario(); // 
    string name = Func.getName(); //data type selected only for explanation
    string sex = Func.getSexo(); // data type selected only for explanation
}
 
Share this answer
 
C#
namespace Zoo
{
    public partial class FuncionarioForm : Form
    {
        List<funcionario> Lfunc;
        List<animal> LAnimal;
        
        public FuncionarioForm()
        {
            InitializeComponent();
            Lfunc = new List<funcionario>();
            LAnimal = new List<animal>();
        }

        private void AdicionarFuncionario_Load(object sender, EventArgs e)
        {

        }         

        private void Refresh()
        {
            listBox1.Items.Clear();
            foreach (Funcionario F in Lfunc)
                listBox1.Items.Add(F.ToString());
            listBox1.Items.Add("----------");
            foreach (Animal A in LAnimal)
                listBox1.Items.Add(A.ToString());
        }

        private void button1_Click(object sender, EventArgs e)
        {


            Funcionario Func = new Funcionario(Func.getNome(),
                                               Func.getSexo(),
                                               Func.getDataNascimento(),
                                               Func.getBi(),
                                               Func.getTelefone(),
                                               Func.getMorada(),
                                               Func.getEmail());

            Lfunc.Add(Func);
            Refresh(); 
        }

This is all code in this part, but i have a class Funcionario with a constructor, and now i want to add the data of Funcionario(employer) that is written in the textbox´s to the listbox and the list!!
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900