在主函数中提示用户输入用户名和密码。另写一方法来判断用户输入是否正确。该方法分别返回一个bool类型的登录结果和和一个string类型的登录信息。如登录成功,返回true及“登录成功”,若登录失败则返回false及“用户名错误”或“密码错误”(使用out参数)
2024-10-09 05:17:26
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace ConsoleApplication7
{
class Program
{
static void Main(string[] args)
{
string result;
Console.WriteLine("请输入用户名");
string name = Console.ReadLine();
Console.WriteLine("请输入密码");
string password = Console.ReadLine();
if (Test(name, password, out result))
{
Console.WriteLine(result);
}
else
{
Console.WriteLine(result);
}
Console.ReadKey();
} static bool Test(string name, string password, out string result)
{
if (name == "admin" && password == "")
{
result = "登录成功";
return true;
}
else if (name == "admin")
{
result = "密码错误";
return false;
}
else
{
result = "用户名错误";
return false;
}
}
}
}
最新文章
- [转载]Javascript异步编程的4种方法
- dp 动态规划 hdu 1003 1087
- ADB连不上,ADB server didn't ACK问题,的解决
- iOS中NSUserDefaults详解
- MySQL设置字符集CHARACTER SET
- dubbo源码之二——dubbo入口
- mysql 二进制安装文件 下载
- 深入理解asp.net SessionState
- mysql忘记root密码 + 授权登录
- poj1182 并查集
- EasyUI - ComboBox 下拉组件
- ucos任务控制块详解
- bisect 二分查找
- [原创软件]Maya报错窗口监测器
- CentOS7安装k8s
- js 检测变量是否存在
- FiDDLER教程
- 【第五课】LNMP环境的入门
- phpredisadmin 莫名其妙错误,打开了无法显示任何数据
- python中如何去掉unicode编码前面的u?
热门文章
- BZOJ 1668: [Usaco2006 Oct]Cow Pie Treasures 馅饼里的财富( dp )
- HTML+CSS笔记 CSS进阶再续
- Aptana jQuery自动提示
- golang并发编程
- Spring Cache使用详解
- 在Spring Boot启动后执行指定代码
- HDU 2104 hide handkerchief
- C# windows ce编程-----我的第一次
- swjtu 1962 A+B(模拟)
- HDU 3032 Nim or not Nim? (sg函数求解)