Link to home
Start Free TrialLog in
Avatar of Halkatla
Halkatla

asked on

Use of unassigned local variable

Hello to all experts! :o)

In a project, I have created my own class to make siblings-objects. A sibling-object shall only be created if the childArray has elements. Why do I get the error "Use of unassigned local variable children" in the writeline-line?

            public static void Main(){
                  string[] childArray = {"child 1", "child 2"};

                  wSiblings children;

                  if (childArray.Length > 0){
                        children = new wSiblings();
                        children.Id = 1;
                  }

                  System.Console.WriteLine(children.Id);
            }

What am I missing or have forgotten about c#-programming?

//Halkatla
ASKER CERTIFIED SOLUTION
Avatar of nikkilocke
nikkilocke

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial