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#

What is wrong with this code.

this code isint a course or anything it isjust some independent work to test my skils but I keep getting an error CS1525. I am trying to make a program tah aks the user to enter there name and if there name is not equal to Michael it will show an error.

thank you.

namespace TreehouseDefense
{
    class Game
    {
        public static void Main()
        {
           string firstName = System.Console.ReadLine();
          System.Console.WriteLine("hello " + firstName + "how are you?");

   System.Console.WriteLine("My firstname is" + firstName);

            if (firstName) != michael;

            {
              System.Console.WriteLine("this is not your account please exit");
            }

        }
    }
}
Rasmus Hall
Rasmus Hall
1,260 Points

you forgot the " on micheal. like this

if (firstName != "micheal");

you wrote

if (firstname) != micheal;

3 Answers

Stuart Wright
Stuart Wright
41,119 Points

I'm not certain but I think in C# the condition in your if statement has to be contained in (). And there definitely shouldn't be a semi-colon at the end of the if condition. Also, I don't see any variable called michael, so perhaps you meant for it to be a string? Try this

if (firstName != "michael") 
{
// Your code here
}

static void Main(string[] args) { string firstName = System.Console.ReadLine(); System.Console.WriteLine("hello " + firstName + "how are you?");

        System.Console.WriteLine("My firstname is" + firstName);

        if (firstName != "michael")  // here

        {
            System.Console.WriteLine("this is not your account please exit");
        }

        Console.ReadLine(); // just to see message before exiting
    }
Rasmus Hall
Rasmus Hall
1,260 Points

you forgot the " on micheal. like this

if (firstName != "micheal");

you wrote

if (firstname) != micheal;