格式化错误

a609091648 2011-12-18 05:11:14
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;
}
}
...全文
85 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
ZhangNan20100811 2011-12-18
  • 打赏
  • 举报
回复
{0] q107770540的眼太牛X了。
a609091648 2011-12-18
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 q107770540 的回复:]
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) + "……
[/Quote]
哎,我居然找了半天找不出来啊、
q107770540 2011-12-18
  • 打赏
  • 举报
回复
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;
}

这种错误犯的太不应该了
a609091648 2011-12-18
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 gxingmin 的回复:]
没看出有啥错误啊,能否把你错误标出来?
[/Quote]
你拷进去运行就知道了、
a609091648 2011-12-18
  • 打赏
  • 举报
回复
你拷贝到程序里一运行就知了、
gxingmin 2011-12-18
  • 打赏
  • 举报
回复
没看出有啥错误啊,能否把你错误标出来?

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧