Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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 14-Jan-13 14:53pm
mibetty480
Edited 14-Jan-13 14:59pm
v2
Comments
jibesh at 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 at 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 !
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
 
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
}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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!!
  Permalink  
v2

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 575
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 369
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,466
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,897


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 15 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100