这样的写法有什么优点呢?

guohuan1816 2012-03-10 09:52:40
新手。请问下下面的构造函数这样写的目的,以及优点是什么?
public Sprite(Texture2D textureImage, Vector2 position, Point frameSize,
int collisionOffset, Point currentFrame, Point sheetSize, Vector2 speed)
: this(textureImage, position, frameSize, collisionOffset, currentFrame,
sheetSize, speed, defaultMillisecondsPerFrame)
{
}

public Sprite(Texture2D textureImage, Vector2 position, Point frameSize,
int collisionOffset, Point currentFrame, Point sheetSize, Vector2 speed,
int millisecondsPerFrame)
{
this.textureImage = textureImage;
this.position = position;
this.frameSize = frameSize;
this.collisionOffset = collisionOffset;
this.currentFrame = currentFrame;
this.sheetSize = sheetSize;
this.speed = speed;
this.millisecondsPerFrame = millisecondsPerFrame;
}
...全文
125 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
newxdlysk 2012-03-11
  • 打赏
  • 举报
回复
1.看起来更清晰
2.可以调用基类的构造函数把this换成base
暖眸 2012-03-11
  • 打赏
  • 举报
回复
顶一楼的。就是这样子的。
lihanbing 2012-03-10
  • 打赏
  • 举报
回复
相当于把millisecondsPerFrame做为可选参数,c++、c#不支持可选参数,所以写成这样

111,126

社区成员

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

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

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