Click here to Skip to main content
Sign Up to vote bad
good
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 - 13:53
mibetty413
Edited 14 Jan '13 - 13:59

Comments
jibesh - 14 Jan '13 - 20:13
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:25
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 !

2 solutions

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  
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  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 OriginalGriff 355
1 Sergey Alexandrovich Kryukov 338
2 Arun Vasu 315
3 Maciej Los 208
4 Aarti Meswania 180
0 Sergey Alexandrovich Kryukov 9,755
1 OriginalGriff 7,549
2 CPallini 4,018
3 Rohan Leuva 3,362
4 Maciej Los 2,951


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