using System;
using System.Windows.Forms;
public class Test
{
static void Main()
{
Rectangle rec1 = new Rectangle(10, 20, 100, 50);
string output = "rec1:";
output += rec1.Print();
rec1.Inflate(20, 20);
output += "rec1Inflate:";
output += rec1.Print();
MessageBox.Show(output, "输出结果");
}
}
//
public class Rectangle
{
private int x;
private int y;
private int width = 10;
private int height = 20;
public Rectangle(int myx, int myy, int mywidth, int myheight)
{
x = myx;
y = myy;
width = mywidth;
height = myheight;
}
public int X
{
set { x = value; }
get { return x; }
}
public int Y
{
set { y = value; }
get { return y; }
}
public int Height
{
set
{
if (value > 0)
height = value;
}
get { return height; }
}
public int Width
{
set
{
if (value > 0)
width = value;
}
get { return width; }
}
public int Area
{
get { return width * height; }
}
public void Inflate(int inwidth, int inheight)
{
X = X - inwidth;
Y = Y - inheight;
Height = Height + 2 * inheight;
Width = width + 2 * inwidth;
}
public string Print()
{
string str = string.Format("X={0},Y={1}.",X,Y)+"\n";
str += string.Format("Width={0],Height={1}.", Width, Height) + "\n";
str += string.Format("Area={0}", Area) + "\n";
return str;
}
}
using System.Windows.Forms;
public class Test
{
static void Main()
{
Rectangle rec1 = new Rectangle(10, 20, 100, 50);
string output = "rec1:";
output += rec1.Print();
rec1.Inflate(20, 20);
output += "rec1Inflate:";
output += rec1.Print();
MessageBox.Show(output, "输出结果");
}
}
//
public class Rectangle
{
private int x;
private int y;
private int width = 10;
private int height = 20;
public Rectangle(int myx, int myy, int mywidth, int myheight)
{
x = myx;
y = myy;
width = mywidth;
height = myheight;
}
public int X
{
set { x = value; }
get { return x; }
}
public int Y
{
set { y = value; }
get { return y; }
}
public int Height
{
set
{
if (value > 0)
height = value;
}
get { return height; }
}
public int Width
{
set
{
if (value > 0)
width = value;
}
get { return width; }
}
public int Area
{
get { return width * height; }
}
public void Inflate(int inwidth, int inheight)
{
X = X - inwidth;
Y = Y - inheight;
Height = Height + 2 * inheight;
Width = width + 2 * inwidth;
}
public string Print()
{
string str = string.Format("X={0},Y={1}.",X,Y)+"\n";
str += string.Format("Width={0],Height={1}.", Width, Height) + "\n";
str += string.Format("Area={0}", Area) + "\n";
return str;
}
}
解决方案 »
- 请问SpVoice语音读文本最大字符串限度是多少?
- 请教一个算法?=“1/200;2/300;3/300;4/500;20/600;23/700;24/700;25/700;26/700”
- datagirdview更新没有成功
- 我用VS2008在调试程序的时候,VS2008会间歇性的假死,难道就是因为盗版?
- SendKeys.SendWait("%{INSERT}");为什么不起作用?
- 请各位给这个小软件估个价。。来着有分。。先来先得。。
- WebService连接Access数据库的问题.急~~~~~~~~~~~~~~
- 我使用ComponentOne For Net中的c1TextBox绑定到字段,但是我想输入Empty字符串,却怎是输入NULL,请问有什么解决办法?
- 分组排列
- 并发调用接口 需要参数和返回值
- 急!!!马上要用,,跪求帮忙!!!!在线等
- 一个简便的更新方式
{
string str = string.Format("X={0},Y={1}.",X,Y)+"\n";
str += string.Format("Width={0],Height={1}.", Width, Height) + "\n";
str += string.Format("Area={0}", Area) + "\n";
return str;
}这种错误犯的太不应该了