作者scottzz (必胜客)
看板C_Sharp
标题Re: [问题] 想要从副函式回传这样的资料
时间Mon Jan 4 21:18:48 2010
※ 引述《awd (672012)》之铭言:
: 感谢您的回覆
: 我照您的方式在副函式类别这样写结构
: 结果有一个小错误,想再提出讨论一下,
: 错误如下:
: ※ 引述《chrisQQ (ChrisLiu)》之铭言:
: : yes 问题如 remmurds 板友所说
: : 改成这样可能会好一点
: : public struct rectangleInfo
: : {
: : private Point _topLeft, _topRight, _bottomLeft, _bottomRight;
: : public rectangleInfo()
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
: 这里出现讯息 错误1 结构无法包含明确无参数的建构函式
: : {
: : this._topLeft = new Point();
: : this._topRight = new Point();
: : this._bottomLeft = new Point();
: : this._botomRight = new Point();
: : }
: : // 也可以在 constructor 就把各点的座标丢进去
: : // 就在依照你希望的格式建个 constructor 罗~
: : public Point topLeft
: : {
: : get { return _topLeft; }
: : set { this._topLeft = value; }
: : }
: : public Point topRight
: : {
: : get { return _topRight; }
: : set { this._topRight = value; }
: : }
: : public Point bottomLeft
: : {
: : get { return _bottomLeft; }
: : set { this._bottomLeft = value; }
: : }
: : public Point bottomRight
: : {
: : get { return _bottomRight; }
: : set { this._bottomRight = value; }
: : }
: : }
: 我自己查一些资料,在msdn上似乎是说一定要有输入参数的表示
: 我找不到其他解法,就自己随便编了一个输入参数试试看 XDD
: 我写成这样
: public rectangleInfo( int x)
: ^^^^^^^^^
: 多写了这部分
: 神奇的是除错可以通过............XDD
: 但其实我也不知道在这里的参数有什麽作用,
: 也没有真的传一个值进去(因为不知道在那里输入...)
: 意外的是在主程式仍可接收到长方形座标回传正确值(感谢~)
: 但自己是有点担心我这样写会不会有什麽不可预期的问题..
: 所以请教各位是否有遇过这样的情况~
: 或是有没有要修正的观念~
: 谢谢~~
结构本来就一定要有带参数的建构子才行.
用以初始内部变数用.
不可以宣告无参数型的建构子!
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 114.39.178.2