using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace structType
{
class Program
{
static void Main(string[] args)
{
Date defaultDate = new Date(); // 使用默认构造器
Console.WriteLine("使用结构的默认构造器输出:{0}", defaultDate);
// 实际上,输出时调用了重写的 ToString 方法
Console.WriteLine("使用结构的默认构造器输出:{0}", defaultDate.ToString());
// 和上句效果一样,上句省略了 ToString 方法
Date weddingAnniversary = new Date(2010, Month.July, 4);
Console.WriteLine("使用自定义的构造器输出:{0}", weddingAnniversary);
// 调用了重写的 ToString 方法
}
}
struct Date
{
private int year; // 0 无效
private Month month; // 0 为枚举类型中的 January
private int day; // 0 无效
public Date(int ccyy, Month mm, int dd)
{
this.year = ccyy - 1900;
this.month = mm;
this.
使用枚举和结构输出日期
最新推荐文章于 2024-10-11 21:14:33 发布