From 49aa18bccd623ab8556074b382d601feba677fb3 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Tue, 7 Jan 2025 20:13:58 -0500 Subject: [PATCH] Make string comparison ordinal, add comment --- SabreTools.DatItems/DatItem.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/SabreTools.DatItems/DatItem.cs b/SabreTools.DatItems/DatItem.cs index 4d10164d..5d9a0dc0 100644 --- a/SabreTools.DatItems/DatItem.cs +++ b/SabreTools.DatItems/DatItem.cs @@ -162,7 +162,9 @@ namespace SabreTools.DatItems if (GetName() == other?.GetName()) return Equals(other) ? 0 : 1; - return string.Compare(GetName(), other?.GetName()); + // If `other?.GetName()` is null, Compare will return > 0 + // If `this.GetName()` is null, Compare will return < 0 + return string.Compare(GetName(), other?.GetName(), StringComparison.Ordinal); } catch { @@ -548,7 +550,9 @@ namespace SabreTools.DatItems if (GetName() == other?.GetName()) return Equals(other) ? 0 : 1; - return string.Compare(GetName(), other?.GetName()); + // If `other?.GetName()` is null, Compare will return > 0 + // If `this.GetName()` is null, Compare will return < 0 + return string.Compare(GetName(), other?.GetName(), StringComparison.Ordinal); } catch {