0
我用asp.net程序,定義了兩個維數組,如何判斷數組值null?如何判斷2維數組在C#中有價值?
數組:
#region inital Festival
string[,] holidays = new string[13, 32];
holidays[1, 1] = "元旦";
holidays[2, 14] = "情人節";
holidays[3, 8] = "婦女節";
holidays[3, 12] = "植樹節";
holidays[4, 1] = "愚人節";
holidays[5, 1] = "勞動節"
holidays[5, 4] = "青年節";
holidays[5, 12] = "護士節";
holidays[5, 14] = "母親節";
holidays[5, 14] = "助殘日";
holidays[6, 1] = "國際兒童節";
holidays[6, 5] = "環境保護日";
holidays[6, 18] = "父親節";
holidays[6, 26] = "國際禁毒日";
holidays[9, 10] = "教師節";
holidays[11, 23] = "感恩節";
holidays[12, 1] = "艾滋病日";
holidays[12, 25] = "聖誕節";
#endregion
有我的代碼:
string holiday = holidays[e.Day.Date.Month, e.Day.Date.Day];
DateTime LunDay = e.Day.Date;
LunDay ld = new LunDay();
if (holiday != string.Empty)
{
//If holiday value not null,add value
}
else
{
//If holiday is null,add tradition date in carlendar
}
我運行代碼,但它跳投添加假期和不添加傳統的日期,如何處理字符串後援.Empty沒有效果。
這是整個代碼:
protected void portalCalendar_DayRender(object sender, DayRenderEventArgs e)
{
t.CurrentCulture = this.oldCulture;
#region inital Festival
string[,] holidays = new string[13, 32];
holidays[1, 1] = "元旦";
holidays[2, 14] = "情人節";
holidays[3, 8] = "婦女節";
holidays[3, 12] = "植樹節";
holidays[4, 1] = "愚人節";
holidays[5, 1] = "勞動節";
holidays[5, 4] = "青年節";
holidays[5, 12] = "護士節";
holidays[5, 14] = "母親節";
holidays[5, 14] = "助殘日";
holidays[6, 1] = "國際兒童節";
holidays[6, 5] = "環境保護日";
holidays[6, 18] = "父親節";
holidays[6, 26] = "國際禁毒日";
holidays[7, 1] = "中共誕辰";
holidays[8, 1] = "建軍節";
holidays[9, 10] = "教師節";
holidays[10, 1] = "國慶節";
holidays[11, 23] = "感恩節";
holidays[12, 1] = "艾滋病日";
holidays[12, 12] = "西安事變";
holidays[12, 25] = "聖誕節";
#endregion
CalendarDay calDay = ((DayRenderEventArgs)e).Day;
TableCell tableCell = ((DayRenderEventArgs)e).Cell;
if (e.Day.IsOtherMonth)
{
e.Cell.Controls.Clear();
}
else
{
try
{
string holiday = holidays[e.Day.Date.Month, e.Day.Date.Day];
DateTime LunDay = e.Day.Date;
LunDay ld = new LunDay();
if (holiday != string.Empty)
{
e.Cell.Controls.Add(new LiteralControl("<br><font color=blue size=2>" + holiday + "</font>"));
//e.Cell.Controls.Add(new LiteralControl("<br>" + ld.GetLunarCalendar(LunDay)));
}
else
{
Response.Write("null holiday");
}
}
catch (Exception exception)
{
Response.Write(exception.ToString());
}
}
}
速記版 - 'if(!string.IsNullOrEmpty(holiday)){}' – Gusdor
謝謝,問題解決了。 – Dolphin