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

Sean Flanagan
Sean Flanagan
33,235 Points

How to compile the code

Hi. How do I get the code to compile please?

using System;

namespace Treehouse.CodeChallenges
{
    class Program
    {
        static void Main()
        {   
            Console.WriteLine("Please enter your name or \"quit\" to exit: ");
            string input = Console.ReadLine();

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

            Console.WriteLine;
        }
    }
}

Thanks.

2 Answers

Seth Kroger
Seth Kroger
56,413 Points

When you call Console.WriteLine at the end you forgot the parentheses.

Sean Flanagan
Sean Flanagan
33,235 Points

Hi Seth. Thanks for your help. I can't believe I made such a stupid mistake.

Thank you both.

Seth Reece
Seth Reece
32,867 Points

Hi Sean,

In workspaces type mcs yourfilename.cs. To run it use mono yourfilename.exe. If using mono or visual studio outside of workspaces I think it's build, or run.

Sean Flanagan
Sean Flanagan
33,235 Points

Hi Seth. Thanks for your reply. I've tried to compile the code without changing its purpose, as per Task 1, but all I get is Program.cs(19,13): error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement Compilation failed: 1 error(s), 0 warnings.

The code is as shown in my original post.