手机
当前位置:查字典教程网 >编程开发 >C#教程 >c#实现输出本月的月历
c#实现输出本月的月历
摘要:格式要求:复制代码代码如下:SUMOTUWETHFRSA010203040506070809101112131415161718192021...

格式要求:

复制代码 代码如下:

SU MO TU WE TH FR SA

01 02 03 04

05 06 07 08 09 10 11

12 13 14 15 16 17 18

19 20 21 22 23 24 25

26 27 28 29 30

代码:

复制代码 代码如下:

class Interview1

{

static void Main()

{

PrintCalender(2011, 10);

}

public static void PrintCalender(int year, int month)

{

formatDate fd = new formatDate(year, month);

string calender =

@"SU MO TU WE TH FR Sa

{0} {0} {0} {0} {0} {0} {0} {0}

{0} {0} {0} {0} {0} {0} {0} {0}

{0} {0} {0} {0} {0} {0} {0} {0}

{0} {0} {0} {0} {0} {0} {0} {0}

{0} {0} {0} {0} {0} {0} {0} {0}";

calender = string.Format(calender, fd).TrimEnd();

Console.WriteLine(calender);

}

}

class formatDate : IFormattable

{

int num;

int max;

public formatDate(int year, int month)

{

DateTime dt = new DateTime(year, month, 1);

num = (int)dt.DayOfWeek * -1;

max = DateTime.DaysInMonth(year, month);

}

public string ToString(string format,IFormatProvider formatProvider)

{

return num++ < 0 || num > max ? " " : num.ToString("00");

}

}

【c#实现输出本月的月历】相关文章:

C#中通过API实现的打印类 实例代码

c#与mysql的连接

服务器端C#实现的CSS解析器

c#实现无标题栏窗口的拖动

C#实现写入与读出文本文件的实例代码

C#+MO实现一些渲染功能

c#在控制台输出彩色文字的方法

C# 实现简单打印的实例代码

深入Resource实现多语言支持的应用详解

使用C#实现在屏幕上画图效果的代码实例

精品推荐
分类导航