Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9256177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:52:48+00:00 2026-06-18T11:52:48+00:00

Got confused why this is giving me error I think my code is correct

  • 0

Got confused why this is giving me error I think my code is correct

XElement outer = new XElement("Main");
XElement xsets;
XElement xsubsets;
foreach (DataRow nav_sets in GetNavigationSets().Rows)
{
    if (nav_sets["parent_id"].ToString() == null)
    {
        xsets = new XElement("Menu", nav_sets["name"].ToString());
    }
    else
    {
        if (int.Parse(nav_sets["id"].ToString()) == int.Parse(nav_sets["parent_id"].ToString()))
        {
            xsubsets = new XElement("SubMenu", nav_sets["name"].ToString());
            foreach (DataRow nav_menus in GetMenusInNavigationSetByNavigation(int.Parse(nav_sets["id"].ToString())).Rows)
            {
                foreach (DataRow menus in GetMenuById(int.Parse(nav_menus["menu_id"].ToString())).Rows)
                {
                    xsubsets.Add(new XElement("MenuItem", menus["name"].ToString()));
                }
            }
        }
        xsets.Add(xsubsets);
    }
    outer.Add(xsets);
}
outer.Save("main.xml");
cn.Close();

The error part shows in this line of code xsets.Add(xsubsets);

Errors:

Error 1 Use of unassigned local variable ‘xsets’
Error 2 Use of unassigned local variable ‘xsubsets’

Got confused how can I get rid of this error.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T11:52:49+00:00Added an answer on June 18, 2026 at 11:52 am

    Change it from

    XElement xsets;
    XElement xsubsets;
    

    to

    XElement xsets = null;
    XElement xsubsets = null;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry for this question. I just got confused by the code to convert or
I was actually going through the question 1636644 .. and got confused with this
I'm relatively confused about this... I've got a table like: +----------------+--------------------------------------------------+------+-----+-------------------+-----------------------------+ | Field |
I have the following code and got myself confused: I have a query that
I was reading this question and the corresponding answer and got confused by the
Hi I got confused to get the explanation for this below, can anyone explain
I was reading this Freuqent Java concurrency problems question and got confused by an
I have checked some tutorials but I got confused by the parameters in this
Have got myself very confused on this one - apologies if the answer is
i was dealing with the following code,& got confused,please have a look at it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.