Questions tagged [icomparer]

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

228 questions
0
votes
2 answers

IComparer based on property of an interface

I have created a class Car that derives form the abstract class TransportMeans and implements an interface PrivateMeans which contains only one property: interface PrivateMean { int capacity { set; get; } } I want to implement a class thet sorts…
arjacsoh
  • 8,932
  • 28
  • 106
  • 166
0
votes
2 answers

Can't create Comparer

I have a class public class PAUserAllowedTimesModel { public List Times { get; set; } public List BusyTimes { get; set; } public DateTime SelectedDate { get; set; } public int DateID { get; set; } } I have…
John
  • 727
  • 2
  • 10
  • 17
0
votes
1 answer

C# Custom Comparer for Tuples Based on Item1

I am working with .Net Framework 4.8 and C# 5.0 I am using SortedSet class objects in my code. They are are defined as SortedSet> sortedSet1; SortedSet> sortedSet2; The struct MyStruct…
PBrenek
  • 561
  • 1
  • 8
  • 24
0
votes
0 answers

Conflicting results found in usage of IComparer being in Console App and Excel DNA

Requiring to build a UDF to be used in Excel, using Excel DNA, to present a result specially sorted in a jagged manner, using C#'s IComparer I was quite surprised as I was not getting a result required as expected. While using the same code in a…
0
votes
2 answers

C# sort with Comparer is giving incorrect result

class Solution { List> ans = new List>(); public List> subsets(List A) { var currList = new List(); A.Sort(); GenerateSubSets(A, 0, currList); ans.Sort(new…
gtestasker
  • 61
  • 7
0
votes
1 answer

Custom Comparer against a parameter failing

I am trying to write a custom comparer to sort a list of search results based on similarity. I would like the term most like the entered search term to appear first in the list, followed by phrases that start with the search phrase, then all other…
duckus
  • 213
  • 3
  • 15
0
votes
0 answers

Using custom comparer with Dictionary and SortedSet

I have a dictionary that maps SortedSet of transactions with transaction status - Dictionary> _transactionsByStatus = new Dictionary>(); I know if I want to intialize…
NUM1NEX
  • 1
  • 1
  • 3
0
votes
0 answers

Is there a way to use the 'in' keyword with delegates, Func<>s or IComparers?

I apologize if the question is poorly-worded, this has been a really hard question to phrase or to search for an answer for and it doesn't help that the 'in' keyword is used for contravarient delegates. This is the best way that I can describe…
0
votes
1 answer

Routine that tests if a point is within a range

Can anyone help me ? for C# I need to implement a routine that tests if a point is within a range ( array ), C# in the figure below the ranges are [1-3],[6-9], [11-15] i would like to use something like binarysearch, i used it but there is a flaw,…
cealex
  • 173
  • 7
0
votes
2 answers

Using IComparer to get index where DateTime is greater than

Given: List descOrderedDates; And a datetime: DateTime fromDate; I can easily count the number of items where the date is greater than fromDate as follows: var count = descOrderedDates.Count(c=> c > fromDate); However I'm struggling to…
Tom Gullen
  • 61,249
  • 84
  • 283
  • 456
0
votes
1 answer

Adapter class or multiple interface implementations for IComparer, IComparer

I need to use a custom sorting algorithm on a WPF DataGrid's ListCollectionView. I created an implementation of IComparer since I use strings but the CustomSort property of ListCollectionView only takes non-generic IComparer…
Zserbinator
  • 365
  • 2
  • 10
0
votes
2 answers

C# / Sorting a text file / IComparer / Custom sort

I have a text file that I want to be sorted. Each line has a package name, a pipe and a version number. Examples: AutoFixture|4.15.0 Castle.Windsor.Lifestyles|0.3.0 I tried to use the default list.Sort() method but I…
ssinfod
  • 975
  • 2
  • 15
  • 31
0
votes
3 answers

Sort ArrayList including custom struct

I wrote a struct public struct SeasonEpisodeNr { public int seasonNr; public int episodeNr; } During my program I will add those structs to an ArrayList. How can I sort them? I tried the IComparer…
theknut
  • 2,533
  • 5
  • 26
  • 41
0
votes
1 answer

How to order an arraylist by versions or dot delimited in VB.NET

I have this kind of imput in my arraylist: 1 1.1 1.1.1 1.1.1.1 1.1.2 1.10 1.11 1.2 1.9 And I want to sort it, to get result looks like this: 1 1.1 1.1.1 1.1.1.1 1.1.2 1.2 1.9 1.10 1.11 I have found possible solutions in other languages but it…
Rchrd
  • 35
  • 1
  • 8
0
votes
2 answers

Comparing two collections of same object in C# and Finding New, Changed or Deleted Records

I have got two collections of same object public class MyClass { public int Id {get;set;} public string Name {get;set;} public int Age{get;set;} public string SSN{get;set;} } I have got two Collections (colA and colB) based on MyClass…