作者chrisQQ (ChrisLiu)
看板C_Sharp
标题Re: [问题] 想要从副函式回传这样的资料
时间Sun Jan 3 00:36:00 2010
: 请问这样可以将每个长方形座标都存进rInfo吗?
理论上可以ˇˇ
: (共有ObjectNum个长方形,希望知道长方形谁是谁)
知道谁是谁的定义是?你每个长方形有自己的名字嘛?
在 ArrayList 中,长方形的顺序就是你加入的顺序
: 如果我要在主函式取出每个长方形的座标
: 请问要如何一个一个分别取出不同的长方形呢?
: 是用for回圈一个一个选出长方形,再提出座标吗?
我原文中是用 foreach 来取出每个长方形,之後再提出座标
你要用 for 的话,应该是这样写
for (int i = 0;i < rectArray.Size ; i++)
{
rectangleInfo ri = (rectangleInfo) rectAray[i];
// ri.topLeft
// ri.topRight
// 看你要怎麽操作了
}
/*
呃,虽然有点不负责任,但如果 rectArray.Size 错的话,
那可能是 rectArray.Length
平常用的 IDE 都有提示语法…
所以没有很仔细记得哪个是 C# 哪个是 Java 的用法…
不好意思 >""<
另外我都是凭着印象写的… 还有问题的话,我过两天再 review code…
*/
: 麻烦您的赐教~
: 再次感谢~
1F:→ a761007:他的写法是C# 3.0才有的 01/02 21:17
2F:→ remmurds:因为Point结构需要透过new关键字产生实体 如果你只有宣告 01/02 23:03
3F:→ remmurds:public Point p { get; set; } 当然会产生编译错误 01/02 23:05
4F:→ remmurds:这跟.Net Framework是不是3.0版没啥关联 01/02 23:07
5F:→ remmurds:也跟set/get写法没啥关连 C#的存取子向来都是长成那样 01/02 23:09
yes 问题如 remmurds 板友所说
改成这样可能会好一点
public struct rectangleInfo
{
private Point _topLeft, _topRight, _bottomLeft, _bottomRight;
public rectangleInfo()
{
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; }
}
}
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 203.145.202.66
※ 编辑: chrisQQ 来自: 203.145.202.66 (01/03 00:39)
※ 编辑: chrisQQ 来自: 203.145.202.66 (01/03 00:47)