题目要求:
关键代码如下所示:
class program { static void main(string[] args) { console.writeline("请输入正确的邮箱地址,以 @sina.com 结尾"); string us =convert.tostring(console.readline()); string str1 = us.replace("@", ""); int count = us.length - str1.length; string str2 = us.replace(".", ""); int count2 = us.length - str2.length; int count3 = us.length - 1; int xl=us.indexof(".")-us.indexof("@"); bool mw = (us.indexof("@sina.com") == (us.length-9)); while (count == 1 && count2 == 1 && us.indexof("@") > 0 && us.indexof(".") > us.indexof("@") && us.indexof(".")<count3) { if (xl != 1 && us.contains("@sina.com") && mw) { console.writeline("正确"); } else { console.writeline("输入的邮箱地址有误"); } break; } console.readline(); } }
以上所述是小编给大家介绍的c#判断email地址是否为合法,希望对大家有所帮助
如对本文有疑问, 点击进行留言回复!!
使用Visual Studio2019创建C#项目(窗体应用程序、控制台应用程序、Web应用程序)
C#实现获取本地内网(局域网)和外网(公网)IP地址的方法分析
网友评论