locked
The name "abcde" does not exist in the current context RRS feed

  • Question

  • Hi there:

    The title (sort of) explains the problem. Below is a portion of my code.

        private void CreateLarzInputFile()
        {
            ...
    
            if (numberOfFrames == 2)
            {
              List<Vector2> SupportsB = UINodesB.FindAll(
                delegate(Vector2 supportb)
                {
                  return supportb.Y == 0;
                }
                );
            }
    
            ...
    
            writer.WriteLine(
              (UIElementsEndB.Count()).ToString() + " " +
              dUINodesB.Count().ToString() + " " +
              SupportsB.Count().ToString() + " " +
              numberOfStoriesB.ToString());
    
            ...
        }
    


    If the If-statement was not there, it worked. After I embedded that first statement with the If-statement, a warning appeared saying "The name "SupportsB" does not exist in the current context."

    Could you please help me? Thanks much!

    Aditya

    • Moved by CoolDadTxModerator Tuesday, August 23, 2011 9:11 PM Language related (From:Visual C# General)
    Tuesday, August 23, 2011 9:04 PM

Answers

  • You've declared SupportsB  inside of the if statement, so it cannot be seen outside of it.
    • Proposed as answer by Dylan-Meeus Tuesday, August 23, 2011 9:37 PM
    • Marked as answer by adityatan Tuesday, August 23, 2011 10:07 PM
    Tuesday, August 23, 2011 9:07 PM
  • Dang I know what's the problem. I have to declare the variable "SupportsB" first of all. 

    Below is the "correct" part of the If-statement.

            List<Vector2> SupportsB = new List<Vector2>();
            if (numberOfFrames == 2)
            {
              SupportsB = UINodesB.FindAll(
                delegate(Vector2 supportb)
                {
                  return supportb.Y == 0;
                }
                );
            }
    


    Cheers,

    Aditya

    Tuesday, August 23, 2011 9:18 PM

All replies

  • You've declared SupportsB  inside of the if statement, so it cannot be seen outside of it.
    • Proposed as answer by Dylan-Meeus Tuesday, August 23, 2011 9:37 PM
    • Marked as answer by adityatan Tuesday, August 23, 2011 10:07 PM
    Tuesday, August 23, 2011 9:07 PM
  • Dang I know what's the problem. I have to declare the variable "SupportsB" first of all. 

    Below is the "correct" part of the If-statement.

            List<Vector2> SupportsB = new List<Vector2>();
            if (numberOfFrames == 2)
            {
              SupportsB = UINodesB.FindAll(
                delegate(Vector2 supportb)
                {
                  return supportb.Y == 0;
                }
                );
            }
    


    Cheers,

    Aditya

    Tuesday, August 23, 2011 9:18 PM
  • I did not see your answer lol. Thanks! I'll mark yours as the answer!

    Aditya

    Tuesday, August 23, 2011 10:07 PM