diff options
Diffstat (limited to 'src/System.Private.CoreLib/shared/System/String.Comparison.cs')
-rw-r--r-- | src/System.Private.CoreLib/shared/System/String.Comparison.cs | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/src/System.Private.CoreLib/shared/System/String.Comparison.cs b/src/System.Private.CoreLib/shared/System/String.Comparison.cs index 6bf3de78fe..d0d49b88a3 100644 --- a/src/System.Private.CoreLib/shared/System/String.Comparison.cs +++ b/src/System.Private.CoreLib/shared/System/String.Comparison.cs @@ -251,14 +251,10 @@ namespace System // to determine whether it is lexicographically less, equal, or greater, and then a // negative integer, 0, or a positive integer is returned; respectively. // - public static int Compare(string? strA, string? strB, CultureInfo culture, CompareOptions options) + public static int Compare(string? strA, string? strB, CultureInfo? culture, CompareOptions options) { - if (culture == null) - { - throw new ArgumentNullException(nameof(culture)); - } - - return culture.CompareInfo.Compare(strA, strB, options); + CultureInfo compareCulture = culture ?? CultureInfo.CurrentCulture; + return compareCulture.CompareInfo.Compare(strA, strB, options); } @@ -269,7 +265,7 @@ namespace System // The case-sensitive option is set by ignoreCase, and the culture is set // by culture // - public static int Compare(string? strA, string? strB, bool ignoreCase, CultureInfo culture) + public static int Compare(string? strA, string? strB, bool ignoreCase, CultureInfo? culture) { var options = ignoreCase ? CompareOptions.IgnoreCase : CompareOptions.None; return Compare(strA, strB, culture, options); @@ -328,7 +324,7 @@ namespace System // beginning at indexB of the same length. Case sensitivity is determined by the ignoreCase boolean, // and the culture is set by culture. // - public static int Compare(string? strA, int indexA, string? strB, int indexB, int length, bool ignoreCase, CultureInfo culture) + public static int Compare(string? strA, int indexA, string? strB, int indexB, int length, bool ignoreCase, CultureInfo? culture) { var options = ignoreCase ? CompareOptions.IgnoreCase : CompareOptions.None; return Compare(strA, indexA, strB, indexB, length, culture, options); @@ -339,13 +335,9 @@ namespace System // at indexA of length length is compared with the substring of strB // beginning at indexB of the same length. // - public static int Compare(string? strA, int indexA, string? strB, int indexB, int length, CultureInfo culture, CompareOptions options) + public static int Compare(string? strA, int indexA, string? strB, int indexB, int length, CultureInfo? culture, CompareOptions options) { - if (culture == null) - { - throw new ArgumentNullException(nameof(culture)); - } - + CultureInfo compareCulture = culture ?? CultureInfo.CurrentCulture; int lengthA = length; int lengthB = length; @@ -359,7 +351,7 @@ namespace System lengthB = Math.Min(lengthB, strB.Length - indexB); } - return culture.CompareInfo.Compare(strA, indexA, lengthA, strB, indexB, lengthB, options); + return compareCulture.CompareInfo.Compare(strA, indexA, lengthA, strB, indexB, lengthB, options); } public static int Compare(string? strA, int indexA, string? strB, int indexB, int length, StringComparison comparisonType) |