【IT168技术文档】
定义的一个主体类:
public delegate decimal CompareCondition(String value); public class StringCompare { private List<IntraString> intraList = new List<IntraString>(); public StringCompare(List<String> strlist) { for (int i = 0; i < strlist.Count; i++) { intraList.Add(new IntraString(strlist[i])); } } public List<IntraString> 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); } }