IComparable.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. // See the LICENSE file in the project root for more information.
  4. using System.Diagnostics.CodeAnalysis;
  5. namespace System
  6. {
  7. // The IComparable interface is implemented by classes that support an
  8. // ordering of instances of the class. The ordering represented by
  9. // IComparable can be used to sort arrays and collections of objects
  10. // that implement the interface.
  11. //
  12. public interface IComparable
  13. {
  14. // Interface does not need to be marked with the serializable attribute
  15. // Compares this object to another object, returning an integer that
  16. // indicates the relationship. An implementation of this method must return
  17. // a value less than zero if this is less than object, zero
  18. // if this is equal to object, or a value greater than zero
  19. // if this is greater than object.
  20. //
  21. int CompareTo(object? obj);
  22. }
  23. // Generic version of IComparable.
  24. public interface IComparable<in T>
  25. {
  26. // Interface does not need to be marked with the serializable attribute
  27. // Compares this object to another object, returning an integer that
  28. // indicates the relationship. An implementation of this method must return
  29. // a value less than zero if this is less than object, zero
  30. // if this is equal to object, or a value greater than zero
  31. // if this is greater than object.
  32. //
  33. int CompareTo([AllowNull] T other);
  34. }
  35. }