用c sharp 写一个登录程序
时间: 2023-12-27 16:48:41 浏览: 19
以下是一个简单的登录程序示例,使用 C# 编写:
```csharp
using System;
class LoginProgram {
static void Main(string[] args) {
string username = "admin";
string password = "12345";
Console.WriteLine("Welcome to the login program!");
Console.Write("Enter your username: ");
string userinput = Console.ReadLine();
Console.Write("Enter your password: ");
string passinput = Console.ReadLine();
if (userinput == username && passinput == password) {
Console.WriteLine("Login successful!");
} else {
Console.WriteLine("Incorrect username or password.");
}
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}
}
```
此程序首先定义了一个用户名和密码,然后提示用户输入他们的用户名和密码。接下来,程序将检查输入是否与预定义的用户名和密码匹配。如果是,程序将输出“登录成功!”;否则,程序将输出“用户名或密码不正确”。最后,程序等待用户按下任意键以退出程序。