小编Mik*_*onn的帖子

在列表中存储一对int

如何在List中存储整数对?我知道我可以像他们一样为他们上课:

class Pair  
{
    int i1,i2;
}
Run Code Online (Sandbox Code Playgroud)

但是,如果我这样做,我将无法使用该Contains函数来检查给定对是否在列表中.我怎么能这样做,所以我可以轻松地将整数存储在List中,并检查一对整数是否已经存在?我不能使用表,因为不知道会有多少对.

编辑:
忘记添加:在我的程序对(x,y)和(y,x)被视为等于.

编辑:
(x,y)和(y,x)是等于检查是否Point在列表中,但是x并且y不能交换,因为x并且y表示两点之间的连接(整数是点的id,不,我不能使用任何参考等...).当我检查是否List包含连接时,如果它是(x,y)或(y,x)并不重要,但稍后我将需要该信息.

c# integer list

21
推荐指数
1
解决办法
3万
查看次数

如何捕捉面板上的鼠标滚轮?

如何在C#中捕获面板上的鼠标滚轮?我正在使用WinForms

编辑:

我现在试着这样做PictureBox.

我的代码:

this.pictureBox1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseClick);    
this.pictureBox1.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseClick);
private void pictureBox1_MouseClick(object sender, MouseEventArgs e)  
  {  
    MessageBox.Show("Click");  
  }
Run Code Online (Sandbox Code Playgroud)

点击即可.催促没有.为什么?

.net c# visual-studio-2010 winforms

21
推荐指数
4
解决办法
5万
查看次数

从没有行的计数中获取0值

我有SELECT:

SELECT c FROM (
    SELECT "candidate_id" as id, count("candidate_id") as c
    FROM "Applicaions"
    GROUP BY "candidate_id"
) as s WHERE id= _SOME_ID_;
Run Code Online (Sandbox Code Playgroud)

但是这只会返回一个值count > 0.如果count = 0它什么也没有返回 如何获得0没有任何申请的"候选人"?

有表"候选人".
如果候选人没有申请或不存在,我需要获得0.

编辑

我现在有了:

SELECT COALESCE ((SELECT count("candidate_id") as c
FROM "Applicaions" WHERE "candidate_id"=_SOME_ID_
GROUP BY "candidate_id"), 0);
Run Code Online (Sandbox Code Playgroud)

它完美地运作.但是有可能把它写得更简单或者这是最好的解决方案吗?我应该创建任何索引吗?

sql postgresql select count

20
推荐指数
3
解决办法
5万
查看次数

DataGridView:如何让一些单元格无法选择?

如何让DataGridView中的某些单元格无法选择?

"不可选择"是指:不能以任何方式选择它并试图选择它不会取消选择任何其他单元格.

我不是故意的ReadOnly.我的单元格已经将此属性设置为true.

DataGridView.MultiSelect 需要是假的.

感谢JYL的回答,我写了一个代码:

    private int selectedCellRow = 0;
    private int selectedCellColumn = 0;

    private void grid_CellStateChanged(object sender, DataGridViewCellStateChangedEventArgs e)
    {
        if (e.Cell == null || e.StateChanged != DataGridViewElementStates.Selected)
                return;

        if (e.Cell.RowIndex == 0 || e.Cell.ColumnIndex == 0 || e.Cell.RowIndex == 1 && e.Cell.ColumnIndex == 1)
        {
            e.Cell.Selected = false;
            grid.Rows[selectedCellRow].Cells[selectedCellColumn].Selected = true;
        }
        else
        {   
            selectedCellRow = e.Cell.RowIndex;
            selectedCellColumn = e.Cell.ColumnIndex;
        }

        //this was only for seeing what is happening
        //this.Text = selectedCellRow + " …
Run Code Online (Sandbox Code Playgroud)

c# datagridview visual-studio-2010 winforms

19
推荐指数
2
解决办法
2万
查看次数

C#Simple Regex - 32个字符,仅包含0-9和af(GUID)

如何在C#中使用正则表达式进行测试:

  • 字符串的长度恰好是32
  • string只包含0-9的数字和af的小写字母

c# regex guid

16
推荐指数
2
解决办法
1万
查看次数

PostgreSQL触发器错误

我有:

CREATE OR REPLACE FUNCTION aktualizujIloscPodan() RETURNS TRIGGER AS
$BODY$ 
  DECLARE 
    n integer;
    sid integer;
BEGIN

sid=0;
IF (TG_OP='INSERT') THEN
sid = NEW."studentID";
ELSIF (TG_OP='DELETE') THEN
sid = OLD."studentID";
END IF;

n = COALESCE ((SELECT count("studentID") as c
FROM "Podania" WHERE "studentID"=sid
GROUP BY "studentID"), 0);

UPDATE "Studenci" SET "licznikpodan" = n WHERE "ID"=sid;
END;
$BODY$ 
LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS triggenPodan ON "Podania";

CREATE TRIGGER triggenPodan AFTER INSERT OR DELETE
ON "Podania"
EXECUTE PROCEDURE aktualizujIloscPodan();
Run Code Online (Sandbox Code Playgroud)

当我尝试执行时:

DELETE FROM …
Run Code Online (Sandbox Code Playgroud)

postgresql triggers

16
推荐指数
2
解决办法
2万
查看次数

循环查找算法

我需要找到一个在给定点开始和结束的循环.不保证它存在.我bool[,] points用来指示哪个点可以循环.点数只能在网格上.points指示网格上的给定点是否可以循环.我需要使用最小点数来找到这个循环.一点只能使用一次.连接只能是垂直或水平.

让这成为我们的观点(红色是起点):

删除死的ImageShack链接

我意识到我可以这样做:

while(numberOfPointsChanged)
{
    //remove points that are alone in row or column
}
Run Code Online (Sandbox Code Playgroud)

所以我有:

删除死的ImageShack链接

现在,我可以找到路径.

删除死的ImageShack链接

但是如果有一些点没有被这个循环删除但不应该在路径中呢?

我写了代码:

class MyPoint
{
    public int X { get; set; }
    public int Y { get; set; }
    public List<MyPoint> Neighbours = new List<MyPoint>();
    public MyPoint parent = null;
    public bool marked = false;
}

    private static MyPoint LoopSearch2(bool[,] mask, int supIndexStart, int recIndexStart)
    {
        List<MyPoint> points = new List<MyPoint>();

        //here begins translation bool[,] …
Run Code Online (Sandbox Code Playgroud)

algorithm graph

14
推荐指数
1
解决办法
1222
查看次数

设置窗口/图片标题

我有:

img = imread('pic.jpg','jpg');
r = img(:,:,1);
g = img(:,:,2);
b = img(:,:,3);

figure, imshow(r);
figure, imshow(g);
figure, imshow(b);
Run Code Online (Sandbox Code Playgroud)

如何在每张图片上设置标题?

matlab image title

11
推荐指数
1
解决办法
2万
查看次数

水平检测算法

你能帮我找到关于如何检测图像上的地平线的任何信息吗?
它不应该基于遗传算法或神经网络.

algorithm image-processing

8
推荐指数
1
解决办法
4225
查看次数

如何在DataGridView控件上获取滚动条的大小?

如何获得控件上显示的垂直滚动条的水平和/或宽度(例如DataGridView)?

c# controls datagridview scrollbar winforms

7
推荐指数
2
解决办法
1万
查看次数