IComparer is an interface provided by the .NET framework, used in conjunction with the Array.Sort and Array.BinarySearch methods. It provides a way to customize the sort order of a collection. It contains a single Compare method that compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other. There is also a generic version of this interface. Supported in .NET 4, 3.5, 3.0, 2.0, 1.1, 1.0. Source: MSDN
Questions tagged [icomparer]
228 questions
0
votes
1 answer
SortedSet add confusion
When I run the code below only 8 of the 50 files in the directory get added.
The files are named like 0001, 0002, 0003, 0004, etc.
The files that get added are in this order: 7,0,1,2,3,4,5,6 when items are no longer added.
Looking at my…

Tom Fobear
- 6,729
- 7
- 42
- 74
0
votes
1 answer
How to order by 2 fields with relation child/parent. Sort it so that child items follow their parents in the sorted list?
I am query in table as below.
Id
BeforeId
Description
For Example:
Id BeforeId Description
1 NULL test
2 NULL test1
3 2 test2
4 3 test3
If BeforeId is not…

binh
- 1
- 3
0
votes
2 answers
Order list on a numerical base
i am using this code to order a list descending on numerical base
ItemsList.OrderByDescending(x => x.Views, new IntComparer());
public class IntComparer : IComparer
{
IComparer Members;
public int Compare(long x, long y)
…

MirooEgypt
- 145
- 1
- 4
- 10
0
votes
1 answer
How to sort WPF GridView alphabetically with empty strings at end?
I have a ListView (GridView) with multiple columns and so far I can sort it by column alphabetically, but when I'm sorting A-Z, empty strings show up at the top. I want to move these to the end. I think I've managed to make an IComparer that will…

grant
- 735
- 8
- 17
0
votes
1 answer
How to use Distinct() in LINQ and how to pass own comparer
I am querying a table called STUDENT.I want to retrieve 2 values, the STUDENT_ID, and the TIME (Both are strings). However, I only want the distinct values of STUDENT_ID. When I use Distinct() with only STUDENT_ID, I do get unique values. But the…
0
votes
2 answers
Compare two objects with custom type in C#
I want to compare two objects with custom type and return the data that has a difference. I override Equals and GetHashCode in Address class and implement a ValueComparer, however the code below returns all data. Please see expected result…

cris gomez
- 131
- 1
- 15
0
votes
1 answer
How to overcome the ArgumentException while sorting using the IComparer interface in C#?
I'm sorting an array of RowRanges using the IComparer. It works fine when the row range is upto 16. Beyond 16, the exception occurs stating that, sorting is not performed and the exception is thrown stating that Soting cannot be performed, because…

Sindhu TN
- 31
- 6
0
votes
2 answers
C# IComparer with respect of the hierarchy
I implement IComparable / IComparer for custom sorting but I need to keep some hierarchy.
My class :
public class Attribut : IComparable
{
public int ATT_ID { get; set; }
public string ATT_LIBELLE { get; set; }
…

WDKyle
- 85
- 1
- 6
0
votes
1 answer
using Icomparer to sort with special condition
In my project i have a need to sort the datagrid column but if a certain condition holds true for an item it should be at the top(first item) of the sorted list. otherwise if that condition does not hold for any item it should be simple sorted…

Fatema
- 135
- 1
- 10
0
votes
3 answers
Sort ObservableCollection values by month name in WPF
I working with WPF and I have an Observablecollection, and myObj class is:
MyObject
{
string happenAtMonth;
int value;
}
happendAtMonth is the name of the month. my observableCollection (MyObColl) will have these values for…

Alaa'
- 487
- 3
- 7
- 16
0
votes
1 answer
Sorting Array with ICompare
This is my first question here, so when i do something wrong, pls be so kind and just say it. So. I have found this in a textbook. Its the Class of an Object Array Sort programm. It's exact the thing i need but it's really poorly explained in the…

Sven
- 1
0
votes
0 answers
Getting Comparer.Default without knowing the type at compile time
I'm writing a comparer library of sorts that can accept any type and compares it. Now I'm creating an ordered comparison which could use Comparer.Default.Compare since it does exactly what I want. How would I go about constructing it without…

Didii
- 1,194
- 12
- 36
0
votes
1 answer
Creating a Custom Sorter for CollectionView.CustomSort in Powershell
I am kinda' new to Powershell and have searched the ends of the earth for a solution, but I can't seem to find anything. I hope it's still doable.
I am trying to sort a CollectionView by date that's in string format. In my custom sorter, I want…

1housand
- 508
- 7
- 16
0
votes
2 answers
I want to understand how the IComparer works in the below program
Given an array of numbers, arrange them in a way that yields the largest value.
Example
{54,546,548,60}
the arrangement is 6054854654 gives the largest value.
class IntegerConcatComparer : IComparer
{
public int Compare(int x, int y)
…

Somasundaram S
- 23
- 3
0
votes
1 answer
IComparer problem + How do I sort an array of strings naturally (FILE_10 > FILE_2) in .NET?
SOLVED at the bottom of my post.
Or more specifically:
I have a bunch of FileInfo objects (I need the FileInfo objects to exclude hidden, system and reparse point files).
I need to sort FileInfo[] naturally based on their FileInfo.FullName. So…

user51710
- 1,153
- 2
- 11
- 20