[英]How do I create a case insensitive list of string?
I'm trying to create a list of string that is case-insensitive. 我正在尝试创建不区分大小写的字符串列表。
The CreateList
method let's me pass in some overloads: CreateList
方法让我传递一些重载:
TComparison<System.string>
IComparer<System.string>
I tried to use TStringComparer.OrdinalIgnoreCase
like this: 我试图像这样使用
TStringComparer.OrdinalIgnoreCase
:
var
List: IList<string>;
begin
List := TCollections.CreateList<string>(TStringComparer.OrdinalIgnoreCase);
end;
But since this comparer doesn't implement any of the above classes / interfaces that doesn't compile; 但是,由于此比较器未实现上面未编译的任何类/接口,因此, I get:
我得到:
E2250 There is no overloaded version of
TCollections.CreateList<System.string>
that can be called with these argumentsE2250没有可以使用这些参数调用的
TCollections.CreateList<System.string>
重载版本
Is there an implementation of one of those available in the spring4d framework? 在spring4d框架中是否可以实现其中之一?
You need to write the parentheses: 您需要写括号:
var
List: IList<string>;
begin
List := TCollections.CreateList<string>(TStringComparer.OrdinalIgnoreCase());
end;
Later compiler versions can figure it out without. 更高版本的编译器可以解决这个问题。
After closer inspection of the type TComparison
: 在仔细检查
TComparison
类型TComparison
:
type
TComparison<T> = reference to function(const Left, Right: T): Integer;
The answer turns out to be quite tivial: 答案非常有野心:
var
List: IList<string>;
begin
List := TCollections.CreateList<string>(AnsiCompareText);
end;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.