using System.Collections.Generic;
public static class Program
private static void Main(string[] args)
var words = new List<string>{"word1 word2", "wordA wordB", "dog cat", "mouse cat"};
var ordered = words.Select(SpecialComparerInstance.Create)
.OrderBy(special => special, SpecialComparer.Default)
.Select(special => special.Value);
foreach (var item in ordered)
public class SpecialComparerInstance
public static SpecialComparerInstance Create(string value) => new SpecialComparerInstance(value);
public SpecialComparerInstance(string value)
if (string.IsNullOrEmpty(value))
throw new ArgumentNullException(nameof(value));
var elements = value.Split(' ');
if (elements.Length != 2)
throw new ArgumentException("Must contain exactly one space character", nameof(value));
FirstOrderValue = elements[1];
SecondOrderValue = elements[0];
public string Value { get; }
public string FirstOrderValue { get; }
public string SecondOrderValue { get; }
public class SpecialComparer : IComparer<SpecialComparerInstance>
public static readonly IComparer<SpecialComparerInstance> Default = new SpecialComparer(StringComparer.Ordinal);
private readonly StringComparer _comparer;
public SpecialComparer(StringComparer comparer)
public int Compare(SpecialComparerInstance x, SpecialComparerInstance y)
if (ReferenceEquals(x, y))
if (ReferenceEquals(x, null))
if (ReferenceEquals(y, null))
var result = _comparer.Compare(x.FirstOrderValue, y.FirstOrderValue);
result = _comparer.Compare(x.SecondOrderValue, y.SecondOrderValue);