【发布时间】:2009-09-11 02:09:38
【问题描述】:
我正在使用 C# Switch 案例,如何使用继承来替换。 案例就像 1,2,3,4 所以 我如何实现它。
例如:
public Blocks(int code)
{
bool[,] shp1;
switch (code)
{
case 1:
this._Width = 4;
this._Height = 1;
this._Top = 0;
this._Left = 4;
shp1 = new bool[_Width, _Height];
shp1[0, 0] = true;
shp1[1, 0] = true;
shp1[2, 0] = true;
shp1[3, 0] = true;
this.Shape = shp1;
break;
case 2:
this._Width = 2;
this._Height = 2;
this._Top = 0;
this._Left = 4;
shp1 = new bool[_Width, _Height];
shp1[0, 0] = true;
shp1[0, 1] = true;
shp1[1, 0] = true;
shp1[1, 1] = true;
this.Shape = shp1;
break;
default:
throw new ArgumentException("Invalid Block Code");
}
}
【问题讨论】:
-
你的问题不是很清楚。请提供更多信息。
-
请更准确。举一个你的开关出现的代码示例。
-
你能解释一下“我如何使用继承替换”的意思吗?
标签: c#