关于设置每年的节日的数组的问题????

kkfd008 2008-06-07 09:34:22
数组用于设置每年的节日

string[][] YearBrithday; //首先初始化
有三种方式设置,可是后期都出问题?
1.
YearBrithday = new string[13][]
for (i=0,i<13,1++)
{
YearBrithday[i] = new string[32]
}


2.
YearBrithday = new string[13][32]
3
YearBrithday = new string[12,31]


第一种和第三种没有报错,第二种直接报错
请问这是为什么???
第一种和第三种有什么区别???
...全文
82 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
kkfd008 2008-06-07
  • 打赏
  • 举报
回复
YearBrithday[2,0] = {"1","2"};
是否正确??
ypacyhero 2008-06-07
  • 打赏
  • 举报
回复
给你个例子:
int[][] a= new int[2][];
a[0] = new int[2] { 1, 2 };
ypacyhero 2008-06-07
  • 打赏
  • 举报
回复
[][] 这种形式是:数组的数组。。也就是说这个数组的元素又是数组。。

[,]表示二维数组。。

这就是区别
smallfz 2008-06-07
  • 打赏
  • 举报
回复
排下格式:
IHolidayItem[] allDays = new IHolidayItem[]{
new GcDay("国际儿童节",6,1),
new GcDay("国庆节",10,1),
new CtcDay("端午节",5,5),
new MothersDay()
/* ..... */
};

public interface IHolidayItem {
bool IsToday { get; }
int DaysLeft { get; }
string Name { get;}
}

/* 公历节日 */
public class GcDay : IHolidayItem {
int _m, _d;
string _name;
internal GcDay(string name, int m, int d) {
_name = name;
_m = m;
_d = d;
}
public string Name { get { return _name; } }
public bool IsToday {
get { return DateTime.Now.Day == _d && DateTime.Now.Month == _m; }
}
public int DaysLeft {
get {
/* 计算下剩余天数并返回...*/
return -1;
}
}
}

/* 农历节日 */
public class CtcDay : IHolidayItem {
int _m, _d;
string _name;
internal CtcDay(string name, int m, int d) {
_name = name;
_m = m;
_d = d;
CtcDateToGcDate(ref _m, ref _d);
}
public string Name { get { return _name; } }
public bool IsToday {
get { return DateTime.Now.Day == _d && DateTime.Now.Month == _m; }
}
public int DaysLeft {
get {
/* 计算下剩余天数并返回...*/
return -1;
}
}
public static void CtcDateToGcDate(ref int m, ref int d){
/* 农历转换成公历.... */
}
}


/* 其他节日,例如母亲节 */
public class MothersDay : IHolidayItem {
public bool IsToday {
get { /* 计算下今天是否5月第二个星期天 */ return false; }
}
public int DaysLeft { get { return -1; } }

public string Name { get { return "母亲节"; } }
}
smallfz 2008-06-07
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 gomoku 的回复:]
不见得string[][]就是好主意。你最好把意图说出来。
[/Quote]

节日有很多种,农历的,公历的,不是具体日期的(如那种某月第某个星期的星期几);
我的解决办法:

[code=C#]IHolidayItem[] allDays = new IHolidayItem[]{
new GcDay("国际儿童节",6,1),
new GcDay("国庆节",10,1),
new CtcDay("端午节",5,5),
new MothersDay()
/* ..... */
};

public interface IHolidayItem {
bool IsToday { get; }
int DaysLeft { get; }
string Name { get;}
}

/* 公历节日 */
public class GcDay : IHolidayItem {
int _m, _d;
string _name;
internal GcDay(string name, int m, int d) {
_name = name;
_m = m;
_d = d;
}
public string Name { get { return _name; } }
public bool IsToday {
get { return DateTime.Now.Day == _d && DateTime.Now.Month == _m; }
}
public int DaysLeft {
get {
/* 计算下剩余天数并返回...*/
return -1;
}
}
}

/* 农历节日 */
public class CtcDay : IHolidayItem {
int _m, _d;
string _name;
internal CtcDay(string name, int m, int d) {
_name = name;
_m = m;
_d = d;
CtcDateToGcDate(ref _m, ref _d);
}
public string Name { get { return _name; } }
public bool IsToday {
get { return DateTime.Now.Day == _d && DateTime.Now.Month == _m; }
}
public int DaysLeft {
get {
/* 计算下剩余天数并返回...*/
return -1;
}
}
public static void CtcDateToGcDate(ref int m, ref int d){
/* 农历转换成公历.... */
}
}


/* 其他节日,例如母亲节 */
public class MothersDay : IHolidayItem {
public bool IsToday {
get { /* 计算下今天是否5月第二个星期天 */ return false; }
}
public int DaysLeft { get { return -1; } }

public string Name { get { return "母亲节"; } }
}[code]
gomoku 2008-06-07
  • 打赏
  • 举报
回复
不见得string[][]就是好主意。你最好把意图说出来。

111,125

社区成员

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

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

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