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
-1
votes
2 answers
Merge ArraList of Objects without dublicates and retaining all filed values from all same objects in Java
I Hava two ArrayList of objects like
ArrayList dataSetOne;
ArrayList dataSetTwo;
Where Records objects looks like
public class Record{
private String id;
private String name;
private String HomeAdrress;
private String…

TechNewBie
- 31
- 2
-1
votes
1 answer
Reasons to not throw when implementing `IComparable`?
Are there any arguments against throwing inside the implementation of IComparable.CompareTo(T value) ?
Does it make sense that Nullable.Compare(null, notNullValue) doesn't throw and why ?

sm_
- 2,572
- 2
- 17
- 34
-1
votes
1 answer
How do i get an element from List elements= new ArrayList<>();?
I want to get the elements from the list.
I'm working right now on a project, next to the Class name is:
> written.
And I do have a ArrayList List list = new ArrayList<>();
But how do I get an element out of the…

dean
- 11
- 3
-1
votes
2 answers
Rewriting an IComparer to use a lambda expression
I'm trying to rewrite my IComparer to use a lambda expression, but I can't seem to get this done correctly
public class AnimalCarriageSorter : IComparer
{
public int Compare(Animal animal, Animal targetAnimal)
{
…

im_ Ruben
- 87
- 2
- 10
-1
votes
1 answer
Use Comparison to compare
I know how to pass Comparison to a Sort.
I want to compare two objects with Comparison. How can I do that?
The class already implements IComparible. This is for a custom comparison.

paparazzo
- 44,497
- 23
- 105
- 176
-1
votes
2 answers
There is no implicit reference conversion from 'dungGenerator.Room' to 'System.IComparable
okay, i followed many tutorial to make it work but i never found a solution.
i have this function in a static class:
public static bool isDifferent(List list1, List list2) where T : IComparable
{
foreach (T item1 in…

Cédric Raymond
- 23
- 7
-1
votes
1 answer
General comparison function, non-type specific, error-tolerant
I'm writing a general alerts system based on user-generated conditions. Test values & actual values are handled as objects since they could be numeric, boolean, or string depending on the selected property. It needs to be error tolerant and fail…

Brendan Hill
- 3,406
- 4
- 32
- 61
-1
votes
3 answers
What interfaces must I implement to make a List or Dictionary concatenate two values as a key
I need to make my custom object work correctly in a Dictionary, List, etc... so that I can change properties of the object, and allow it to be resorted, and not orphaned.
The last time I attempted overriding GetHashCode(), I orphaned objects when I…

makerofthings7
- 60,103
- 53
- 215
- 448
-2
votes
2 answers
Implementing Icomparable on a Taxpayer class to sort based on taxOwed
i am not being able to implemenet Icomparable CompareTo to compare Taxpayer objects based on tax owed ..can someone help me with the icomparable implementatioin of Taxpayer class??
I want to implement the icomparable like here-Interfaces is new…

Anjana Sharma
- 4,535
- 5
- 37
- 51
-2
votes
1 answer
WPF DataGrid - Custom Sorting with DataTable as ItemsSource
Using a DataGrid, I display a DataTable with content generated at runtime. I therefore cannot use predefined columns. Each row contains a name as its first element and then a variable number of data that are usually numeric but may also be null or…

japhwil
- 299
- 4
- 16
-2
votes
2 answers
Primitives and IComparable interface
In Java if I wanna sort any data independent to its data type I would use Comparable interface and I found out we have similar interface in C#, so I have simple sorting algorithm:
public static void Sort(IComparable[] arr)
{
bool swap = true;
…

Skyglar
- 135
- 3
- 12
-2
votes
2 answers
How does icomparer implementing class decide sorting order on the array items?
How does the return value of IComparer.Compare function decide the order of sorting operation? What is the significance of return values in deciding the sorting order? How does the flow of Array.Sort() happen?
For example, :
int[] ii = new int[3] {…

psin
- 59
- 8
-2
votes
2 answers
Sort a single instance of a class with multiple arrays
I thought I'd find everything I need on sorting online, but this one eludes me. I have a single instance of a class. The class has two arrays. I have to sort the combined two elements of the class based on one of the two arrays. It's easy to sort a…

JohnC.IT
- 33
- 5
-2
votes
2 answers
Sort List using the property of its property
I have a model:
public class SomeClass {
public List Owner {get; set;}
public int Balance {get;set;}
. . . .
}
and
public class Person {
public string Name {get;set;}
public Guid PersonID {get;set;}
. . . .
}
I have a wrapper…

xGeo
- 2,149
- 2
- 18
- 39
-2
votes
1 answer
Custom common number-text comparer in C# to sort numeric/string list?
I want to create a similar number-text comparer to the one described in How to create custom common number-text comparer in C# to sort numeric/string list?.
public class NumberTextComparer : IComparer
{
public int Compare(string…

Sanvi Deshpande
- 3
- 2