Defines a generalized comparison method that a value type or class implements to create a type-specific comparison method for ordering instances.
Questions tagged [icomparable]
264 questions
0
votes
1 answer
SortedSet.Contains gives error "at least one object must implement ICombarable"
I have two SortedSets:
SortedSet> sset1 = new SortedSet>();
SortedSet> sset2 = new SortedSet>();
Later on I check I make a new Sorted set:
SortedSet newSset =…

Aelion
- 379
- 1
- 5
- 16
0
votes
3 answers
Define how a comparison operator is applied to a type?
How can I define whether and how a comparison operator is applied to operands of my type?

osvein
- 625
- 2
- 10
- 31
0
votes
1 answer
how to create a IComparable[] in c#?
public static void sort(IComparable[] a)
{
int N = a.Length;
for (int i = 0; i < N; i++)
{
for (int j = i; j > 0 && less(a[j], a[j - 1]); j--)
{
exch(a, j, j - 1);
}
isSorted(a, 0, i);
}
…

iamtonyzhou
- 49
- 5
0
votes
1 answer
Why does a generic and a non-generic IComparable interface exist?
Perhaps this question sounds silly, but why does a generic and a non-generic IComparable interface exist?
Furthermore, which one is prefered to use and why?

John Threepwood
- 15,593
- 27
- 93
- 149
0
votes
1 answer
IComparabale sorts in unexpected order
I'm sorry but I think I'll have to stick in a lot of code into my question. The good news is though, if you have the time, you can just copy this into a Console Application and execute it so you can see the issue with the results.
I have been given…

Dave
- 8,163
- 11
- 67
- 103
0
votes
4 answers
.NET 3.5 - Object not implementing IComparable?
When converting a project (in which a template method of IComparable was used a few times) from VS 2005 to VS 2008 I've got some errors:
Error 12 Type argument 'Object' does not inherit from or implement
the constraint type…

brovar
- 811
- 4
- 10
- 25
0
votes
1 answer
Comparer.Compare needs one Object that implements IComparable but will throw exception if not the first parameter is
In the documentation for Compare function in Comparer class it says:
If a implements IComparable, then a. CompareTo (b) is returned; otherwise, if b implements IComparable, then the negated result of b. CompareTo (a) is returned.
But when I test…

zwi
- 1
0
votes
1 answer
Hide the sort of a collection in VB.NET
In the following example i would like to hide the .sort() method to the client, how could i achieve that ?
Namespace test
Class Figure
Implements IComparable(Of Figure)
Public Property Area As Double
Public Function CompareTo(ByVal…

peter
- 41,770
- 5
- 64
- 108
0
votes
3 answers
Extending the comparable generic
I'm developing a template based classes in Java that implement various trees structure (such as standard binary tree, red-black tree or B-Tree). My idea is to have it done like various lists in Java Collections. That is one interface class which is…

Robin92
- 533
- 1
- 6
- 20
0
votes
4 answers
Comparing two custom objects
public class Filter
{
public int A { get; set; }
public int B { get; set; }
public DateTime Start { get; set; }
public DateTime End { get; set; }
}
What is the best way, to compare two Filter objects according with sometimes one,…

Saint
- 5,397
- 22
- 63
- 107
0
votes
2 answers
IComparable IgnoreCase
I'm writing a function to compare 2 values of IComparable type, and throwing if not equal. Basically, re-making assert. Yes, I'm aware I'm reinventing the wheel.
public static void IsEqual(T Value1, T Value2) where T : IComparable
{
…

Sperry
- 317
- 1
- 3
- 16
0
votes
3 answers
Problems comparing objects using IComparable
Here is some code I'm trying to get working. If an item in one set doesn't match an item in the other set a 0 is added to a list for all items compared. If in the end the list doesn't contain any other values than 0 it means the item from the first…

Willem
- 81
- 2
- 9
0
votes
1 answer
What sorting strategy should I use for this case?
I have a list of strings that presents name of categories that a film belongs to. I make a class define that list, implement List and IComparable interface, in order to use in PivotViewerStringProperty as below:
public class SLCategoryList :…

ducnh
- 260
- 1
- 3
- 10
-1
votes
1 answer
How to sort a custom list - SecondaryItem within PrimaryItem
Hi there have a list of custom objects that I need to be able to sort, one property within another. How do I go about doing this using .Net. Normally I would carry out all sorting requirements within the SQL that delivers the data, unfortunately…

Paul Johnson
- 29
- 3
-1
votes
1 answer
Using IComparer to compare 2 IEnumerables with 1 comp obj
I'm looking for a way to create a method which should compare for example 2 strings with 1 comparable string and return 1, 0 or -1 (if the value is greater than, equal to, or less than). The method should look like this:
int…

RRuseva
- 25
- 5