将VB程序的特定行转换为C#

时间:2017-08-10 08:16:05

标签: c# vb.net comparison emgucv contour

您好我正在编写一个基于VB程序的C#程序来识别图像中的文本。但是,我似乎无法弄清楚这一行的C#等价物:

listOfContoursWithData.Sort(Function(oneContourWithData, otherContourWithData) oneContourWithData.boundingRect.X.CompareTo(otherContourWithData.boundingRect.X))

这是ContourWithData类,listOfContoursWithData是以下实例:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Emgu.CV.Util;

namespace TrainAndTest
{
    public class ContourWithData
    {
        const int MIN_CONTOUR_AREA = 100;

        public VectorOfPoint contour;    // contour
        public System.Drawing.Rectangle boundingRect;    // bounding rect for contour
        public double dblArea;   // area of contour

        public bool checkIfContourIsValid(){
        if ((dblArea < MIN_CONTOUR_AREA))
            return false;
        else
            return true;
    }
}

1 个答案:

答案 0 :(得分:2)

您可以使用lambda表达式:

listOfContoursWithData.Sort((oneContourWithData, otherContourWithData) => 
                                oneContourWithData.boundingRect.X.CompareTo(otherContourWithData.boundingRect.X));

List<ContourWithData>.Sort()方法以Comparison<ContourWithData>为参数。这是一个委托,将两个ContourWithData个实例作为输入并返回int