c# – 我的示例中使用什么数据结构
发布时间:2020-12-15 04:24:47 所属栏目:百科 来源:网络整理
导读:我想创建一个组件,它由一块板和它的周围角落组成.板的大小(因此也是边界的大小)在运行时定义.一些例子(板子很亮,边框很暗): alt text http://img340.imageshack.us/img340/3862/examplegw.png 该板由BoardCell类型的对象组成,边框由BorderCell类型的对象组
我想创建一个组件,它由一块板和它的周围角落组成.板的大小(因此也是边界的大小)在运行时定义.一些例子(板子很亮,边框很暗):
alt text http://img340.imageshack.us/img340/3862/examplegw.png 该板由BoardCell类型的对象组成,边框由BorderCell类型的对象组成.电路板的数据结构是BoardCell [,] – 一个简单的二维数组. 我怎样才能代表边界?我从这样的事情开始: public BorderCell TopLeft // top left corner cell public BorderCell TopRight // top right corner cell public BorderCell BottomRight // bottom right corner cell public BorderCell BottomLeft // bottom left corner cell public BorderCell[] Top // top border (without corners) public BorderCell[] Bottom // bottom border (without corners) public BorderCell[] Left // left border (without corners) public BorderCell[] Right // right border (without corners) 我不喜欢这种边界的表现,你能提出更好的建议吗? 附加:我想在边框对象上有一个方法SetSomethingForTheCell: public void SetSomethingForTheCell(...) 但是根据我目前的数据结构,我不知道该作为参数传递什么. 解决方法
由于检测细胞是否是边界的一部分确实很简单,只需存储一次细胞并在需要时测试边界成员资格.
测试单元格是否在边框中的简单方法: // assuming that the array is in row-major order... public static bool IsInBorder(this BoardCell[,] board,int x,int y) { return x == board.GetLowerBound(1) || x == board.GetUpperBound(1) || y == board.GetLowerBound(0) || y == board.GetUpperBound(0); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- oracle – ORA-01799:一个列可能没有外连到子查询
- c++10进制转换为任意2-16进制数字的实例
- postgresql-操作符
- 【error】No 'Access-Control-Allow-Origin' 跨域问
- 几种常用的xml配置,Spring,Struts,Mybatis,sitemesh
- c – 按值或按引用传递容器
- vue vue-Router默认hash模式修改为history需要做的修改详解
- U-Boot第一阶段关键代码理解(绿色加粗为自己添加)
- oracle 中使用单引号(')和双引号(")
- C#命名空间/文件夹:何时过于有组织/创建太多名称空间不对?