StringSegmentComparerCreate(CultureInfo, Boolean) 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: 10.0.0
C#
public static StringSegmentComparer Create(
	CultureInfo culture,
	bool ignoreCase
)

Parameters

culture  CultureInfo
A culture whose linguistic rules are used to perform a comparison.
ignoreCase  Boolean
to specify that comparison operations be case-insensitive; to specify that comparison operations be case-sensitive.

Return Value

StringSegmentComparer
A new StringSegmentComparer object that performs string comparisons according to the comparison rules used by the culture parameter and the case rule specified by the ignoreCase parameter.

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