Goto 的用法记录

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Goto_Contiune_Break
{
    class Program
    {
        /// <summary>
        /// goto 跳转做的一个登录
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            int count = 1;     //记录错误登录次数
            Logo:
            Console.WriteLine("请输入登录ID");
            string userID = Console.ReadLine();
            Console.WriteLine("用户名:{0}", userID);

            Console.WriteLine("请输入登录密码");
            string userPwd = Console.ReadLine();
            Console.WriteLine("userPassword:{0}", userPwd);

            if (userID == "admin" && userPwd == "admin")
            {
                Console.WriteLine("欢迎用户{0}的到访!", userID);

            }
            else
            {
                if (count <= 2)
                {
                    Console.WriteLine("输入的账号或者密码不正确,请重新输入");
                    count++;
                    goto Logo;
                }
                else
                { 
                    Console.WriteLine("输入错误的次数大于3, 当前用户ID被锁定 3分钟,3分钟后在尝试登录");
                    Console.ReadLine();
                }
            }
            Console.ReadLine(); 
        }
    }
}

 

posted @ 2024-07-10 14:51  逯文杰  阅读(3)  评论(0编辑  收藏  举报