Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C# C# Basics (Retired) Perfect Variable Scope

Program.cs(11,13):error CS0103: The name`input'does not exist in the current context ->try {input = Console.ReadLine();}

input exist in the try scope !!

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {            

            try 
            {

            input = Console.ReadLine();

            if (input == "quit")
            {
                string output = "Goodbye.";
            }
            else
            {
                string output = "You entered " + input + ".";
            }

            Console.WriteLine(output);
        }
            catch(FormatException)
                    {

                        continue;
                    }
        }
    }
}

1 Answer

Steven Parker
Steven Parker
231,248 Points

You have not declared the variable input yet.

That's what the error message is trying to tell you. Before (or when) you assign input you must declare it with a "var" or "string" keyword.

You'll find a few other things to fix in this challenge. Remember:

  • a variable must be declared before it is used.
  • a variable can only be declared once, but can be assigned multiple times
  • a variable should be declared in the outermost scope in which it is used

Thanks for answering!

Steven Parker
Steven Parker
231,248 Points

And did you pass the task?