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

Variable Scope Code Challenge

I am stuck on this code challenge and cant seem to figure out what it is wanting me to do. If I run the code as is I get "Program.cs(19,12): error CS1524: Unexpected symbol Console', expectingcatch' or `finally' Compilation failed: 1 error(s), 0 warnings" If anyone can help me understand this i would greatly appreciate it.

Program.cs
using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {            
            input = Console.ReadLine();
            try
            {
                if (input == "quit")
                {
                    string output = "Goodbye.";
                }
                else
                {
                    string output = "You entered " + input + ".";
                }
            }
            Console.WriteLine(output);
        }
    }
}

2 Answers

Steven Parker
Steven Parker
231,210 Points

:point_right: When you add try, you also need to add catch.

For a "try" block to be effective, and to compile correctly, it would be followed by a "catch" block. But adding "try" and "catch" is not part of this challenge.

This challenge is about fixing errors in variable scope. Look for places where a variable is used in one scope but declared in another, or declared more than once.

Okay, do you have any idea which video I should watch to maybe get a better grasp on declare a variable?

You should put String type to variable "input" also.