IComparable interface defines a generalized comparison method that a value type or class implements to create a type-specific comparison method for ordering instances.
Questions tagged [icomparablet]
6 questions
7
votes
2 answers
How do I apply a default IComparable in a Linq OrderBy clause
I have a type which has a default sort order as it implements IComparable and IComparable. I'm not getting the results I expect from LINQ , basically it looks as if the IComparable which the type implements is not being applied.
I thought I…

Mike
- 101
- 1
- 5
6
votes
4 answers
C# boxing enum error with generics
I don't understand what is going on here...
I've got the following error:
The type 'TestApp.TestVal' cannot be used as type parameter 'T' in the generic type or method 'TestApp.SomeClass'. There is no boxing conversion from 'TestApp.TestVal' to…
Jake Jeffries
4
votes
4 answers
Difference between IComparable and IComparable in this search method
I know that there is a big difference between IComparable and IComparable in general, see this, but in this search method it will not make any difference, or will it?
public static int Search(List a, T target) where T : IComparable
{
…

Dieter Meemken
- 1,937
- 2
- 17
- 22
2
votes
2 answers
FxCop and IComparable/IComparable
I'm currently investigating the use of FxCop with one of our existing projects and am getting an odd result.
The output displays a small number of breaches of the 'Override methods on comparable types' rule stating "'Log' should override Equals…

DilbertDave
- 3,406
- 3
- 33
- 42
1
vote
1 answer
How do I implement IComparable?
I've created my own generic Java data structure library, now I'm creating it in C#, but I'm stuck trying to implement the CompareTo method to sort a singly linked list.
Here's my code:
class SortedSinglyLinkedList : IComparable // my class
//…

92AlanC
- 1,327
- 2
- 14
- 33
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