StringSegmentComparerCreate(CultureInfo, CompareOptions) Method

Creates a StringSegmentComparer object that compares strings according to the rules of a specified culture.
Please note that the returned StringSegmentComparer may allocate new strings in some cases when targeting older frameworks. See the Remarks section for details.

Definition

Namespace: KGySoft.CoreLibraries
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 9.0.0
C#
public static StringSegmentComparer Create(
	CultureInfo culture,
	CompareOptions options
)

Parameters

culture  CultureInfo
A culture whose linguistic rules are used to perform a comparison.
options  CompareOptions
Specifies the options for the comparisons.

Return Value

StringSegmentComparer
A new StringSegmentComparer object that performs string comparisons according to the comparison rules used by the cultureoptions parameters.

Remarks

If culture is either the InvariantCulture or the CurrentCulture, then depending on the targeted platform, the GetHashCode(StringSegment) and GetHashCode(ReadOnlySpanChar) methods might allocate a new string. In .NET Core 3.0 and above none of the members of the returned StringSegmentComparer will allocate new strings.

If culture is any CultureInfo other than the InvariantCulture and CurrentCulture, then depending on the targeted platform, the GetHashCode(StringSegment), GetHashCode(ReadOnlySpanChar), Equals(ReadOnlySpanChar, ReadOnlySpanChar) and Compare(ReadOnlySpanChar, ReadOnlySpanChar) methods might allocate a new string. In .NET Core 3.0 and above none of the members with StringSegment parameters will allocate new strings. And methods with ReadOnlySpanT parameters (Equals(ReadOnlySpanChar, ReadOnlySpanChar) and Compare(ReadOnlySpanChar, ReadOnlySpanChar)) can avoid allocating strings when targeting .NET 5.0 or higher.

See Also