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

  • SEARCH
  • Home
  • 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 7726355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:11:33+00:00 2026-06-01T05:11:33+00:00

I am facing a problem related to the scope of the variables used .

  • 0

I am facing a problem related to the scope of the variables used .

code:

   int row_no, upflag, downflag;
        for (int i = count; i > 0; i--)
        {
            asd = ds1.Tables[out_table].Rows[i][59].ToString();
            int com1 = string.Compare(asd, "Upstream");
            int com2 = string.Compare(asd, "Downstream");
            if (com1 == 0 || com2 == 0)
            {
                row_no = i;
                if (com1 == 0)
                    upflag = 1;
                else
                    downflag = 1; 
                break;
            }

        }
        if (upflag == 1)//
        {
            string val1 =  ds1.Tables[out_table].Rows[count][59].ToString();
            string val2 = ds1.Tables[out_table].Rows[(count - 1)][59].ToString();
        }

in this code, in the last if(upflag == 1) condition, my VS2010 shows a red line below the upflag and said
use of unassigned local variable ‘upflag’.

why is it so? It was perfectly ok in c++ , but here under multiple nested loops/condition, the value assigned to the variable inside the brackets, does not reflect back outside them, even when the variable is declared before the loop.

Please help

  • 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-01T05:11:34+00:00Added an answer on June 1, 2026 at 5:11 am

    Consider what happens if count == 0. The body of the for loop will not be executed, and no value will be assigned to upflag. That’s why the compiler said “use of unassigned local variable” – it means it is possible that the variable was not assigned.

    It was perfectly ok in c++

    No, it wasn’t. The compiler might not have complained about it, but it was still undefined behaviour.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am facing with problem related Http Connection. MY code : URL url =
I'm facing a problem with EF's related entities. I have the following code: public
Iam facing problem in understanding and converting a matlab code into opencv. I want
iam facing problem in passing array to view. this is my controller code.. function
I am facing problem to get variable from query string. I have used htaccess
I am facing a strange and weird problem related with the UITextField's Autocorrection. I
I am facing with a problem related startActivityForResult() To start SecondActivity from FirstActivity :
I'm currently facing a variable substitution related problem in groovy. While this is quite
I am facing a problem related to get out all the controls from some
I am facing a peculiar problem related to a hosted WCF service (.NET Framework

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.