日期:2014-05-19  浏览次数:20766 次

构造函数重载的问题?
using   System;
///   <summary>
///   Test8   的摘要说明。P112
///   继续上一章网络用户的例子,为网络用户类添加注册功能,注册时对用户输入的ID进行合法性检查:
///   小写字母开头,只能由字母、数字和下划线组成,并验证用户两次输入密码是否相同。
///   </summary>
class   T9Testx8
{
static   void   Main(string[]   args)
{
Webuse   use1=new   Webuse();
string   id,pwd1,pwd2;
try
{
Console.Write( "注册开始:\nID由字母、数字和下划线组成且,首字母为小写字母;2次输入密码必须相同。\nPlease   intput   your   Id: ");
id=Console.ReadLine();
Console.Write( "Please   intput   your   Password: ");
pwd1=Console.ReadLine();
Console.Write( "Please   validate   your   Password   : ");
pwd2=Console.ReadLine();
if(id== " ")
{
throw   new   Excepbb();
}
else   if(use1.logging_on(id,pwd1,pwd2)==true)
{
use1=new   Webuse(id,pwd1);
use1.Show(use1);
}
else
Console.WriteLine( "Logging   on   is   defeated ");
}
catch(Excepbb)
{
Console.WriteLine( "您未输入ID! ");
}
catch(FormatException   e)
{
Console.WriteLine(e.Message);
}
finally
{
Console.WriteLine( "-*-*-*-*-*-*-*-*- ");
Console.WriteLine( "     Program   over     ");
Console.WriteLine( "-*-*-*-*-*-*-*-*- ");
Console.ReadLine();
}
}
internal   class   Webuse
{
string   id,pwd;
string   email;
internal   Webuse()
{
id= "boaby_tdk ";
pwd= "19491001 ";
email=Convert.ToString(pwd)+ "@heav.com ";
}
internal   Webuse(string   youId,string   youPassword)
{
id=youId;
pwd=youPassword;
email=Convert.ToString(youId)+ "@heav.com ";
}
internal   bool   logging_on(string   useid,string   password1,string   password2)
{
string   id,pwd1,pwd2;
bool   flag=true;
try
{  
id=useid;
pwd1=password1;
pwd2=password2;
if(id[0] < 'a '   ||   id[0]> 'z ')
{
flag=false;
throw   new   ErrIdStr();
           
}
else   if(pwd2!=pwd1)
{
flag=false;
throw   new   ErrPwd();
}
for(int   i=0;i <id.Length;i++)
{
if(id[i]> = 'a '   &&   id[i] <= 'z '   ||   id[i]> = 'A '   &&   id[i] <= 'Z '   ||   id[i]> = '0 '   &&   id[i] <= '9 '   ||   id[i]== '_ ')
{
flag=true;
}
else
{
flag=false;
throw   new   ErrId();
}
}
}
catch(ErrIdStr)
{
Console.WriteLine( "ID首字母错误,只能是小写字母! ");
}
catch(ErrId)
{
Console.WriteLine( "ID字母只能是字母、数字和下划线! ");
}
catch(ErrPwd)
{
Console.WriteLine( "2次输入的密码不一样! ");
}