首页 > 解决方案 > if 和 else 语句输出相同的问题

问题描述

我一周前开始编程,并陷入了一个 if else 相关的问题。我写的代码是:-

Console.WriteLine("hello, what is your username?");
  string name = Console.ReadLine();
    Console.WriteLine("hi, " + name + " nice to meet you!");
    
    Console.WriteLine("please enter your password");
   string password = Console.ReadLine();
   if (password == "blablabla")
   {
    Console.WriteLine("you are signed in");
   }
   else;{
    Console.WriteLine("incorrect password");}

而且,在输出中,即使我输入了正确的密码,它也会显示“您已登录”以及“密码错误”。请告诉我我做错了什么,谢谢:)

标签: c#if-statement

解决方案


从 else; 中删除逗号“;” 那将


推荐阅读