请问我这个程序是否有内存溢出?

clyde_lulu 2007-12-07 12:05:14
这是一个用C#编写的,用NUnit进行单元测试的程序。要实现对一个日期加一,判断是否合法。请问我这个程序是否有内存溢出?是否还有别的问题?应该如何修改?

using System;
using NUnit.Framework;

namespace NextDate
{
class DateType
{
public int year;
public int month;
public int day;

public DateType(int y, int m, int d)
{
year = y;
month = m;
day=d;
}
}

class NextDate
{
public bool leap(int y)
{
if (y % 100 == 0 && y % 400 == 0)
return true;
if (y % 100 != 0 && y % 4 == 0)
return true;
return false;
}

public DateType plus(DateType today)
{
bool c1,c2;
DateType tomorrow=new DateType(0,0,0);
tomorrow.year = today.year;
tomorrow.month = today.month;
tomorrow.day = today.day;

c1=(1<=today.day) && (today.day<=31);
c2 = (1 <= today.month) && (today.month <= 12);
if(c1==false)
return new DateType(0,0,0);
if(c2==false)
return new DateType(0,0,0);

switch(today.month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
if(today.day<31)
tomorrow.day=today.day+1;
else
{
tomorrow.day=1;
tomorrow.day=today.month+1;
}
break;
case 4:
case 6:
case 9:
case 11:
if(today.day<30)
tomorrow.day = today.day + 1;
else
{
tomorrow.day = 1;
tomorrow.day = today.month + 1;
}
break;
case 2:
if(today.day<28)
tomorrow.day = 1;
else
{
if(today.day==28)
{
if(leap(today.year))
tomorrow.day=29;
else
{
tomorrow.day=1;
tomorrow.month=3;
}
}
else
if(today.day==29)
{
tomorrow.day=1;
tomorrow.month=3;
}
else
return new DateType(0,0,0);
}
break;
}

return tomorrow;
}
}

[TestFixture]
class Program
{
[Test]
public static void Main(string[] args)
{
NextDate a = new NextDate();

Assert.AreEqual(new DateType(2001, 4, 15), a.plus(new DateType(2001, 4, 15)),"aa");
}
}
}
...全文
36 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
clyde_lulu 2007-12-07
  • 打赏
  • 举报
回复
请高手指教。

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧