抽象类判断日期能否被2整除
时间:2011-02-20 来源:zisouTags
A类
public abstract class modA
{
public abstract int datetimeforday();
protected string str = string.Empty;
public string iloveyou(int type)
{
switch (type)
{
case 0:
str= "能被2整除";
break;
case 1:
str ="不能被整除";
break;
}
return str;
}
}
B类重载:
public class modB:modA
{
public override int datetimeforday()
{
int i = -1;
i = (int)DateTime.Now.Day;
return i;
}
}
INDEX.ASPX.cs
View Code1 modB mb = new modB();
2 Response.Write("今天日期"+mb.datetimeforday()+","+mb.iloveyou(Convert.ToInt32(mb.datetimeforday() % 2)));
B类继承A类并重载方法datetimeforday()获取日期方法。
输出时调用整除2.
相关阅读 更多 +