查找匹配度最高的字符串

查找匹配度最高的字符串 -- 代码
定义的一个主体类:
 public delegate decimal CompareCondition(String value);
    public class StringCompare
    {
        private List intraList = new List();
        public StringCompare(List strlist)
        {
            for (int i = 0; i < strlist.Count; i++)
            {
                intraList.Add(new IntraString(strlist[i]));
            }
        }
        public List Compare(CompareCondition condition)
        {
            for (int i = 0; i < intraList.Count; i++)
            {
                intraList[i].Compare(condition);
            }
            intraList.Sort(delegate(IntraString a, IntraString b)
            {
                if (a.CompareResult > b.CompareResult)
                {
                    return 1;
                }
                else if (a.CompareResult == b.CompareResult)
                {
                    return 0;
                }
                else
                {
                    return -1;
                }
            }
            );
            return intraList;
        }
    }
    public class IntraString
    {
        private String value;
        public IntraString(String value)
        {
            this.value = value;
        }
        public String Value
        {
            get { return value; }
            set { this.value = value; }
        }
        private decimal compareResult;
        public decimal CompareResult
        {
            get { return compareResult; }
            set { compareResult = value; }
        }
        public void Compare(CompareCondition condition)
        {
            CompareResult = condition(Value);
        }
    }
 

你可能感兴趣的:(搜索引擎,string,class)