我使用C#切換大小寫如何使用繼承來替換。 情況就像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");
}
}
你的問題不是很清楚。請提供更多信息。 – rahul 2009-09-10 12:07:32
請更精確。給出一個你的開關出現的代碼示例。 – cedrou 2009-09-10 12:07:35
你能澄清一下你的意思嗎?「我如何使用繼承來替換」? – 2009-09-10 12:08:01