在主函数中提示用户输入用户名和密码。另写一方法来判断用户输入是否正确。该方法分别返回一个bool类型的登录结果和和一个string类型的登录信息。如登录成功,返回true及“登录成功”,若登录失败则返回false及“用户名错误”或“密码错误”(使用out参数)
2015-12-18 21:01
1521 查看
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 == "123") { result = "登录成功"; return true; } else if (name == "admin") { result = "密码错误"; return false; } else { result = "用户名错误"; return false; } } } }
相关文章推荐
- 17-1 UI高级可视化设计
- 15 UITabBarController、block高级(+UIMenuController_UIPasteBoard、MBProgressHud)
- 14-1 UITableView综合-模态viewController、单例(LED,Neon)
- 组件_ UIToolbar 与 组件_UISearchBar
- UITableView的使用
- 13 自定义cell、cell自适应高度、 多种类型的cell混合使用、 UITableViewController、model类
- <LeetCode OJ> 303. Range Sum Query - Immutable
- 12 UITableView编辑和移动 、UITableViewController、(+UIDatePicker)
- 11 UITableView表视图
- UIPickerView
- UIStoryboard和UIResponder
- UIImageView和UIImage
- 10 导航控制器UINavigationController、导航条navigationBar、界面通信(属性传值、代理传值、单例传值)
- UIAlertView与UIActionSheet
- 09 UIScrollView 、 UIPageControl
- 08-2 UISwitch and UIStepper
- IOS 开发学习笔记-基础 UI(十)九宫格布局,块动画,字典转模型,Xib使用
- 08-1 UIControl 及其子类 UISegmentedControl 、UISlider
- UIScrollView的使用
- 07 手势识别器、UIImageView、(transform)、模拟button内部实现触摸事件