2016-06-11 7 views
-3

ログイン端末を作っているのでログイン文字列があるので、 :ユーザ入力が定義済みの文字列であることを確認する

Console.WriteLine("--------------------"); 
Console.WriteLine("---LOGIN TERMINAL---"); 
Console.WriteLine("--------------------"); 
System.Threading.Thread.Sleep(1000); 
Console.WriteLine("/Log In"); 
Console.WriteLine("/Create New User"); 
Console.WriteLine("/Delete User"); 

userInput = Convert.ToString(Console.ReadLine()); 
if(userInput = LogIn) 
{ 

} 
+0

はありがとうございました!とにかく感謝しています。 –

答えて

0

= operatorは代入演算子です。等価演算子である== operatorを使用する必要があります。

if(userInput == LogIn) 
{ 

} 

このLogInは変数ではなく、stringは、次のような二重引用符でそれを使用する必要がある場合。

if(userInput == "LogIn") 
{ 

} 
+0

通常、VSはあなたにこのトラップのヒントを与えます.... –

+0

@FalcoAlexanderはい、等価チェックではなく割り当てをしていないことを警告する拡張機能もあります。 –

0

これは役立つはず:

Console.WriteLine("--------------------"); 
Console.WriteLine("---LOGIN TERMINAL---"); 
Console.WriteLine("--------------------"); 
System.Threading.Thread.Sleep(1000); 
Console.WriteLine("/Log In"); 
Console.WriteLine("/Create New User"); 
Console.WriteLine("/Delete User"); 

var userInput = Convert.ToString(Console.ReadLine()); 
if(userInput == "Log In") // input check here 
{ 
    Console.WriteLine("Enter User Name"); 
    var userName = Console.ReadLine(); 
    Console.WriteLine("Enter User Password:"); 
    var password = Console.ReadLine(); 
    Console.WriteLine("User Name: {0}, Password: {1}", userName, password); 
} 
関連する問題