icomparable Questions

3

Solved

I'm implementing IComparable and IComparable<T> in one of my classes. Is there any recommendation on how the CompareTo method in each case should behave when given a null argument? Should it ...
Aeolipile asked 27/12, 2011 at 7:19

3

Solved

Should I implement both IComparable and the generic IComparable<T>? Are there any limitations if I only implement one of them?
Highpowered asked 4/9, 2011 at 18:27

2

Solved

I can implicitly cast an int to a IComparable. I can also cast a List or an array to a IEnumerable. But why can't I implicitly cast a List to a IEnumerable? I tested this with the .net framework ...
Cassicassia asked 22/2, 2013 at 16:51

6

What is the difference between IComparable and IComparer Interfaces? Is it necessary to use this interface always with Array.Sort() method
Compartment asked 12/5, 2011 at 15:51

3

For my project, I first load an image from file, and put every pixel into a 2D pixels[,] array. Then, I want to examine each pixel and split them up into "bins" based on how they are colored, and t...
Farnsworth asked 30/11, 2012 at 22:45

1

Solved

I'm receiving a null object in my custom IComparer implementation despite no null entries in the collection it is being applied to. My understanding is this can be caused by inconsistencies in the ...
Plante asked 15/11, 2012 at 22:31

3

Solved

Could anyone explain me what's wrong in the following class declaration: private class PriorityQueueEntry<TPriorityValue,IIdentifiableEntry,IType> : IComparer<PriorityQueueEntry<TPrio...
Parang asked 13/11, 2012 at 12:44

1

Solved

Ok, I have a simple IEnumerable<HtmlString> things and I want to divide it up into four equal groups. var quarter = things.OrderBy(t => t.Foo).Count() / 4; should do the trick, but instea...
Tael asked 21/9, 2012 at 21:6

3

Solved

I have a couple of classes that implement an interface, IFoo. I need to display a list of objects of these classes in a table, which I'd like to be able to sort by any arbitrary column in the table...
Kickshaw asked 29/2, 2012 at 15:50

2

Solved

Basically I have the following: public static bool IsBetween<T>(this T value, T a, T b) where T : IComparable { ... } public static bool IsBetween<T>(this T value, T a, T b) where ...

2

Solved

I am very new to generics and I am trying to write a simple class which will be generic but also allow sorting of some description on a string member variable. At the moment I have a basic class ...
Gynaecomastia asked 1/2, 2012 at 10:26

3

Solved

I want to check if a type supports IComparable before sorting it, but I've found that checking if a type supports the IComparable interface using "is" does not always give me the correct answer. Fo...
Saw asked 31/7, 2011 at 15:10

3

Solved

This might be a trivial question, but I didn't find any information about this: is it "harmful" or considered bad practice to make a type T implement IComparable<S> (T and S being two differe...
Counterproposal asked 29/3, 2010 at 16:18

4

Solved

Most people, when writing a refence type (class) which implements IComparable<T>, use the convention that null is LESS than any actual object. But if you try to use the opposite convention, s...
Tonry asked 31/5, 2011 at 15:14

2

Solved

Could anyone please advise when implementing something like IComparable in .NET what sorting algorithm does .NET use to actually sort the underlying data? Also is the algorithm used customiza...
Connieconniption asked 11/5, 2011 at 3:2

2

Solved

I am working on a extension method where it finds the min item by specific selector. Below the code public static T MinBy<T, K>(this IEnumerable<T> src, Func<T, K> selector) whe...
Assembled asked 24/2, 2011 at 6:55

2

Solved

I'm trying to create a simple Clamp (so that I can bound the values of anything comparable ... mostly for number types such as int, double, etc.) The problem is if I do the following I get an erro...
Jenjena asked 20/7, 2010 at 21:37

1

Solved

I'm here to ask a specific topic - I really found few info about this on the web. I'm implementing a F# version of Minimax algorithm. The problem I'm having now is that I want to compare Leaf of my...
Laxation asked 22/6, 2010 at 13:14

4

Solved

e.g. The code below throws a ClassCastException when the second Object is added to the TreeSet. Couldn't TreeSet have been written so that the type parameter can only be a Comparable type? i.e. Tre...
Biotic asked 13/4, 2010 at 19:3

4

Solved

I have a class that implements IComparable. public class MyClass : IComparable<MyClass> { public int CompareTo(MyClass c) { return this.whatever.CompareTo(c.whatever); } etc.. } I th...
Diarmit asked 19/3, 2010 at 19:40

6

Solved

I'm scrubbing 5 files for a specific value. I dont anticipate any different values, BUT since this is for my own educational purposes, I would like the application to count, compare and print the m...
Latreshia asked 24/1, 2010 at 5:42

4

Solved

I am implmenting the IComparable to sort like typed objects. My question is why does it cast type person to int32? The array's Sort() seems to cast each type in the array to the type that I am usin...
Michaelemichaelina asked 12/12, 2009 at 19:9

1

Solved

Ok, I have these intersection methods to work with ranges, and they work well as long as the range endpoints are not null: public static bool Intersects<T>(this Range<T> first, Range&l...
Ranunculaceous asked 13/11, 2009 at 14:1

3

Solved

I have a List<MyObj> with the class MyObj : IComparable. I wrote the method CompareTo in the MyObj class per the IComparable interface, but when I use the List<MyObj>.Contains(myObjInst...
Subtractive asked 2/7, 2009 at 19:51

5

When I want to constraint the type T to be comparable, should I use: where T : IComparable or where T : IComparable<T> I can't get my head around if #2 makes sense. Anyone can explain w...
Brooklet asked 27/5, 2009 at 16:52

© 2022 - 2024 — McMap. All rights reserved.