for (int i = 0; i < numOfHours; i ++)
{
for (int a = 0; a < NUM_DAYS; a ++)
{
Color colour;
if (NUM_DAYS == SATURDAY)
{
//It says that this is unreachable
colour = Color.LightBlue;
}
else
{
colour = Color.White;
}
SolidBrush fill = new SolidBrush(colour);
Pen outline = new Pen(Color.Black);
paper.FillRectangle(fill, a * apptWidth, i * apptHeight, apptWidth, apptHeight);
paper.DrawRectangle(outline, a * apptWidth, i * apptHeight, apptWidth, apptHeight);
}
}
我不知道为什么它不会改变颜色变量。我设置了一个日历,它会根据他们一天有多少小时绘制一个网格,因此行将是他们的小时数,列将是天数。我想更改代表星期六的框的颜色。提前谢谢您。
最佳答案
大概 NUM_DAYS
和 SATURDAY
都是常量,因此 if 语句中的表达式始终返回 false(因为看起来它们并不相同)。
我想你的意思是:
if (a == SATURDAY)
关于c# - 检测到无法访问的代码,if 语句中的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37235731/