Tuesday, May 3, 2022

List sorting

List sorting

    Examples and Concepts

  1. IComparer<T > Interface
  2. Defines a method that a type implements to compare two objects.

  3. Comparison<T > Delegate
  4. Represents the method that compares two objects of the same type.

    Type Parameters T The type of the objects to compare. This type parameter is contravariant. That is, you can use either the type you specified or any type that is less derived.

  5. How to sort a list in C# | List.Sort() Method Set -1
  6. List<T >.Sort() Method is used to sort the elements or a portion of the elements in the List <T > using either the specified or default IComparer <T > implementation or a provided Comparison <T > delegate to compare list elements. There are total 4 methods in the overload list of this method as follows:

  7. How to sort a list in C# | List.Sort() Method Set -2
  8. List<T >.Sort() Method is used to sort the elements or a portion of the elements in the List <T > using either the specified or default IComparer < T > implementation or a provided Comparison <T > delegate to compare list elements. There are total 4 methods in the overload list of this method as follows:

  9. List <T > Class
  10. Represents a strongly typed list of objects that can be accessed by index. Provides methods to search, sort, and manipulate lists.

  11. ArrayList.Sort Method
  12. an good example:Sorts the elements in the ArrayList or a portion of it.

    three overloads. need to play with them..

  13. CaseInsensitiveComparer Class
  14. Compares two objects for equivalence, ignoring the case of strings.

    Basics

  15. IComparer Interface
  16. Exposes a method that compares two objects.

  17. IComparable Interface
  18. Defines a generalized type-specific comparison method that a value type or class implements to order or sort its instances.

  19. IComparable.CompareTo(Object) Method
  20. Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.

    A value that indicates the relative order of the objects being compared. The return value has these meanings:
    Less than zero: This instance precedes obj in the sort order.
    Zero This instance occurs in the same position in the sort order as obj.
    Greater than zero This instance follows obj in the sort order.

    Notes to Implementers For objects A, B and C, the following must be true:

    1. A.CompareTo(A) must return zero.
    2. If A.CompareTo(B) returns zero, then B.CompareTo(A) must return zero.
    3. If A.CompareTo(B) returns zero and B.CompareTo(C) returns zero, then A.CompareTo(C) must return zero.
    4. If A.CompareTo(B) returns a value other than zero, then B.CompareTo(A) must return a value of the opposite sign.
    5. If A.CompareTo(B) returns a value x not equal to zero, and B.CompareTo(C) returns a value y of the same sign as x, then A.CompareTo(C) must return a value of the same sign as x and y.

  21. Use the IComparable and IComparer interfaces in Visual CSharp
  22. This article describes the use of IComparer and IComparable interfaces in Visual C#.

  23. Sort list by field (C#)
  24. How to sort easily my refSortNodeList by m_valRating field? Or maybe I need to use some another List class?

  25. C# IComparable Example
  26. Use the IComparable generic interface. This helps with custom sorting algorithms.

  27. IComparable, IComparer And IEquatable Interfaces In C#
  28. During implementation, often question rises on how to sort a collection of objects. To sort a collection requires how objects can first of all be compared to each other. A value type such as int, double, float can be compared if both of the objects have equal values. However, a reference type such as a class with multiple fields, the question is often difficult to answer. Well, in other words it depends. It depends how two objects are said to be compared / equated; when all fields have the same value or one of them is enough to decide if they are equal.

  29. Using IComparable and IComparer to compare objects
  30. In this article I will try to provide some techniques according to the effective use of the IComparable and the IComparer interfaces in a development context and I will expose some real use cases to know how, and under witch condition may one use each of both interfaces.

  31. Comparing C# types – IComparable or IComparer
  32. How to make best of the interfaces provided by .NET framework for comparison types? In this article I will discuss why to use IComparable or IComparer interfaces or to be more precise difference between IComparable and IComparer. And why do we need to compare types in .NET at first place.Lets’s start checking all the aspects one by one by using C# examples.

  33. System.Collections.Generic.IComparer
  34. Provides additional comparison mechanisms This allows you to provide ordering of your class on several fields or properties, ascending or descending order on the same field or both.

  35. IComparer <T > Interface
  36. Defines a method that a type implements to compare two objects.

  37. C# IComparer
  38. C# IComparer tutorial shows how to compare values in C# with IComparer interface.

  39. Using IComparer for sorting
  40. The code errors out. Apparently it is expecting IComparer <Point > as argument to sort method. What do I need to do to fix this?

    More examples

  41. Sort a List by a Field in C#
  42. This article will introduce how to use the C# Sort() function and LINQ’s OrderBy() keyword to sort a list in ascending and descending order.

  43. Sort a list of objects by multiple fields in C#
  44. This post will discuss how to sort a list of objects against the multiple fields in C#.

  45. How to use the IEqualityComparer
  46. I have some bells in my database with the same number. I want to get all of them without duplication. I created a compare class to do this work, but the execution of the function causes a big delay from the function without distinct, from 0.6 sec to 3.2 sec!

  47. IEqualityComparer<T > Interface
  48. Defines methods to support the comparison of objects for equality.

  49. C# IEqualityComparer
  50. Use a custom IEqualityComparer to implement specialized lookup behavior for Dictionary.

  51. Introduction To Generic IEqualityComparer
  52. IEqualityComparer is a very important interface for comparer tasks in the LinQ world. The next extended methods have an overload with this parameter type: Contains, Distinct, Except, Intersect, GrouBy, GroupJoin, Join, SecuenceEqual, ToDictionary, ToLookUp and Union.

  53. Write And Use IEqualityComparer in C#
  54. Equality might seem straightforward, but it tends to get fuzzier the longer you think about it. When it comes to programming, there are two general thoughts around equality.

  55. How to sort an Array in C# | Array.Sort() Method Set – 1
  56. Array.Sort Method is used to sort elements in a one-dimensional array. There are 17 methods in the overload list of this method as follows:

  57. ArrayList in C#
  58. ArrayList is a powerful feature of C# language. It is the non-generic type of collection which is defined in System.Collections namespace. It is used to create a dynamic array means the size of the array is increase or decrease automatically according to the requirement of your program, there is no need to specify the size of the ArrayList. Or in other words, ArrayList represents an ordered collection of an object that can be indexed individually. In ArrayList, you can store elements of the same type and of the different types. It belongs to the non-generic collection. The below diagram illustrates the ArrayList class hierarchy:

  59. C# | ArrayList Class
  60. ArrayList represents an ordered collection of an object that can be indexed individually. It is basically an alternative to an array. It also allows dynamic memory allocation, adding, searching and sorting items in the list.

  61. C# | Array vs ArrayList
  62. Arrays: An array is a group of like-typed variables that are referred to by a common name.

  63. Array.Sort Method
  64. Sorts the elements in a one-dimensional array.

No comments:

Post a Comment