C# yes 邮箱问题

已有如下代码,按要求增加功能:

static void Main(string[ ] args)

{

      string email;   // 电子邮件地址  

      Console.WriteLine("请输入你的邮箱:");

      email = Console.ReadLine();

      Console.WriteLine("你的邮箱是 {0}", email);   

}

需实现的功能:

1、 输入 yes 时,程序循环执行

2、 兼容以下各种形式 yes(YES、yes、 YeS …..)

3、 提取邮箱的用户名

实现代码如下:

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

namespace 学习
{
    class Program
    {
        static void Main(string[] args)
        {
            string email;
            while (true)
            {
                Console.WriteLine("询问是否继续?");
                string isgoon = Console.ReadLine();
                isgoon.ToLower();
                if (isgoon == "yes")
                {
                    Console.WriteLine("请输入你的邮箱(name@***.com):");
                    email = Console.ReadLine();
                    Console.WriteLine("你的邮箱为{0}", email);
                    int j = email.IndexOf("@");
                    Console.Write("你的用户名为:");
                    Console.WriteLine(email.Substring(0, j));
                }
                else
                    break;
            }
        }
    }
}

 

posted on 2013-11-18 23:36  Forgiving  阅读(287)  评论(0编辑  收藏  举报