Hey Guys,
My DataView is acting funny and it is sorting things alphabetically and I need it to sort things numerically. I have looked all across the web for this one and found many ideas on how to sort it with ICompare, but nothing really solid.
So my questions are
How do I implement ICompare on a DataView (Looking for code here).
...
Guys and dolls,
I am wondering how to naturally sort a DataView... I really need help on this. I found articles out there that can do lists with IComparable, but I need to sort the numbers in my dataview.
They are currently alpha sorted because they are numbers with 'commas' in them. Please help me out.
I would like to find somethi...
First, two examples:
// This works
int foo = 43;
long lFoo = foo;
// This doesn't
object foo = (int)43;
long? nullFoo = foo as long?; // returns null
long lFoo = (long)foo; // throws InvalidCastException
if (foo.GetType() == typeof(int))
Console.WriteLine("But foo is an int..."); // This gets written out
Now, my guess as to why t...
I'm trying to create a Quicksort base class using VB.NET, taking it an array of IComparable elements. The signature looks like this:
public shared sub Sort(ByVal values() as IComparable)
However, when I pass in an array of doubles, the compiler is giving me errors.
Dim numbers(100) as double
Dim random as new Random(0)
for i as in...
I have some generic types, like the following:
public struct Tuple<T1, T2> { ... }
public struct Tuple<T1, T2, T3> { ... }
etc.
These should in theory be able to compare themselves against other values of the same type, so that I can write the following type of code:
List<Tuple<Type, String>> l = new List<Tuple<Type, String>>();
l.Ad...
I need a basic example of how to use the IComparable interface so that I can sort in ascending or descending order and by different fields of the object type I'm sorting.
...
I'm trying to figure out which of these interfaces I need to implement. They both essentially do the same thing. When would I use one over the other?
...
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 since it implements IComparable."
There are two issues with this:
I thought that it was on...
I'm trying to use Set operations with a class that I have. Every instance of this class has a unique ID. Do I need to implement the System.IComparable interface and if so how would I?
type SomeClass(id : int) =
member this.ID = id
let someSet = Set.of_list [SomeClass(1); SomeClass(2)]
let test = someSet.Contains(SomeClass(2))
...
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 what the difference would be?
...
Currently I have an object implementing the IComparable interface (ASP.NET 3.5, VB). When I place several instantiated objects into a Generics list, I sort them by doing a simple someList.Sort. My CompareTo() function is this:
Public Function CompareTo(ByVal obj As Object) As Integer Implements
System.IComparable.CompareTo
'default is...
I have a helper function, which basically calls CompareTo on two objects, but does some special corner case checking, converting, etc.
Originally I wrote the function as such:
public static bool BetterCompare(IComparable lhs, IComparable rhs, out retCode)
{
...
retCode = lhs.CompareTo(rhs);
...
}
But the problem is that i...
Hi,
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(myObjInstance) it returns false when it should be true.
I'm not sure I'm understanding how I need to proceed to make sure the List uses my custom comparison...
I have an interface IScriptItem that implements IComparable<IQueueItem>.
In my eyes it would seem enough to have IComparable items in order to have a sorted anything. But all I can find is Dictionaries, Hashtables and SortedLists that are actually SortedTrees.
What I'm looking for is a sorted generic list that takes IComparables.
Am I l...
I'm trying to sort an ArrayList of custom items and get 'At least one object must implement IComparable.' despite having implemented the IComparable interface for them. I'm just calling the default Sort() no parameters or anything. The definition of the object I'm trying to sort is as follows:
class AssetItem : System.IComparable<Asse...
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 it It seams like it will demand that the first input implements
Icomparable. Following ...
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 'System.IComparable'.
Is this an actual fact that System.Object no longer implements that interface, or somethi...
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<T> second, IComparer<T> comparer)
{
return comparer.Compare(first.Start, second.End) <= 0
&& comparer.Compare(first.End, second.Start) >= 0;
}...
How to implement IComparable to sort numerical and non-numerical string.
Firstly, I want to get the Min and Max value in the "list".
It is asking me to implement ICompareable. " At least one object must implement IComparable"
Can anyone help me? Here is my code:
// setup
string filePath1 = Directory.GetCurrentDirector...
Anyone have any opinions on whether or not IEquatable or IComparable should generally require that T is sealed (if it's a class)?
This question occurred to me since I'm writing a set of base classes intended to aid in the implementation of immutable classes. Part of the functionality which the base class is intended to provide is autom...