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
1
vote
3 answers
String.Replace and Regex.Replace not working with special characters inside IComparer
The following console app works fine:
class Program
{
static void Main(string[] args)
{
string plainx = "‘test data’ random suffix";
plainx = Regex.Replace(plainx, @"‘", string.Empty);
Console.WriteLine(plainx);
…

Sekhar
- 5,614
- 9
- 38
- 44
1
vote
1 answer
compare method list with array
Background to the problem:
Im currently working on a pathfinder. My lastest implementation was the ability to load in different mapfiles instead of only using one array containing the map. So before it looked like this:
Node[] mMatrix;
However…

LamaCoder
- 223
- 1
- 18
1
vote
2 answers
Casting Error when sorting with IComparer
I have an ArrayList of strings of the form "Q19_1_1", "Q19_10_1", "Q19_5_1".
With the normal sort method the list will be sorted as
"Q19_1_1"
"Q19_10_1"
"Q19_5_1"
But I would like to sort it numerically based off the second integer in name and…

Zifendale
- 140
- 2
- 12
1
vote
1 answer
vb.net TreeView IComparer
Why oh why doesn't this work? I found it on MSDN butit throws an exception:Unable to cast object of type 'OutlookTemplates.com.NodeSorter' to type 'System.Collections.IComparer'.
Public Class NodeSorter
Implements IComparer(Of…

aelgoa
- 1,193
- 1
- 8
- 24
1
vote
1 answer
Sorting a list in C# with Icomparer
I want to sort the items in a combobox on the object.Frequency. I did some research and then I made this class:
public class CompareByFrequency : IComparer
{
public int Compare(GenderFrequency x, GenderFrequency y)
{
…

user2740565
- 67
- 1
- 1
- 3
1
vote
2 answers
Sorting custom list with bool
There is a class
public class Camera
{
...
public bool live;
...
}
This is the sorting class
public class CameraSortByLive : IComparer
{
private bool asc;
public CameraSortByLive(bool a)
{
this.asc = a;
…

Pablo
- 28,133
- 34
- 125
- 215
1
vote
3 answers
Reverse-sorting a Listview (with Comparer class)
I have a two-column ListView linked to a Datapager. The ListView lists all files of a particular type in a particular directory, so the data source is an ArrayList of type FileInfo. Consequently, I had to create a Comparer class to use in the…

CJM
- 11,908
- 20
- 77
- 115
1
vote
2 answers
How can I change the Comparer of ASP.NET's Request.Form collection?
ASP.NET's Request.Form["key"] collection uses a case-insensitive Comparer. This is screwing me up because I've got form POST data that looks like:
"subject=MySubjectLowerCase&Subject=MySubjectUpperCase"
As a result, Request.Form["subject"] (or…

Howiecamp
- 2,981
- 6
- 38
- 59
1
vote
1 answer
Using IComparable in vb.net for comparing weapons for Rock, Paper and Scissors game (same as Comparable in JAVA)
I'm new to programming and OOP so please forgive me for my lack of knowledge.
As part of my Rock, Paper and Scissors game I would like to create a abstract superclass (Weapon) which has subclasses (Rock, Paper and Scissors) in VB.NET. I found the…

AJsStack
- 271
- 1
- 5
- 27
1
vote
2 answers
IComparable with Enums sent as generic type parameters (C#)
Possible Duplicate:
When are two enums equal in C#?
I have the following classes as part of a simple state machine.
Please note that all generic type parameters HAVE to be an enumeration. That has been enforced in the constructors (not shown…

Raheel Khan
- 14,205
- 13
- 80
- 168
1
vote
3 answers
Sort String Array As Int
Is there some way to use IComparer with ArrayList.Sort() to sort a group of strings as ints?
Ferdinand de Aragon
1
vote
1 answer
SortedList Compare
I have two sortedlists
1. oldlist
2. newlist
(application specific information - key is industryId and value is weight)
I want to compare the changes in the lists.
I want the following things -
list of items where weight was…

Bilal Fazlani
- 6,727
- 9
- 44
- 90
1
vote
1 answer
Sort/orderby nodes in xml using IComparer
I need to sort nodes in xml. I have the following code which successfully orders them alphabetically. However, much of the data is numeric although strings are allowed. I have a IComparer set up that works to correctly sort data as I wish it to…

RememberME
- 2,092
- 4
- 37
- 62
1
vote
2 answers
Problem with custom IComparer for List (sort) - c#
can anyone help, i have problem doing a sort, I thought i had it sorted but appears not to be working.
I have a List which stores the following values
8,6,10,11,7
I also have another List (accessories in my class and it has a propert called…

mark smith
- 20,637
- 47
- 135
- 187
0
votes
1 answer
How can I change the default IComparer in an MVC project?
In an ASP.net MVC3 project I have a custom implementation of the IComparer interface. I want to use my comaprer by default when strings are sorted. How can I change the default IComparer for the project?

Tarzan
- 4,270
- 8
- 50
- 70