加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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);
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读