icomparable Questions
8
Solved
I am populating an array with instances of a class:
BankAccount[] a;
. . .
a = new BankAccount[]
{
new BankAccount("George Smith", 500m),
new BankAccount("Sid Zimmerman", 300m)
};
Once I popu...
Austen asked 15/11, 2010 at 19:24
4
Solved
I have an object called Shape which contains a public int[,] coordinate { get; set; } field.
I have a separate class which has a collection of Shape objects. At a particular point, I wish to check...
Faustofaustus asked 6/8, 2013 at 5:31
2
Solved
I'm trying to implement the same example of this link but more oriented on the number of dependent kids.
http://www.codeproject.com/Articles/42839/Sorting-Lists-using-IComparable-and-IComparer-Int...
Karolinekaroly asked 11/11, 2014 at 15:38
4
Solved
I have code like this -
List<User> users;
protected class User : IComparable<User>
{
public string name;
public string email;
public decimal total;
public string address;
public ...
Webb asked 31/7, 2014 at 15:59
5
Solved
Both the interfaces seem to compare objects for equality, so what are the major differences between them?
Nesmith asked 9/3, 2010 at 15:21
6
Solved
I've noticed these two interfaces, and several associated classes, have been added in .NET 4. They seem a bit superfluous to me; I've read several blogs about them, but I still can't figure out wha...
Raymond asked 31/8, 2010 at 14:9
4
Solved
Anyone have any opinions on whether or not IEquatable<T> or IComparable<T> should generally require that T is sealed (if it's a class)?
This question occurred to me since I'm writing a...
Cephalization asked 8/12, 2009 at 16:56
5
Is there any LINQ support for checking if an IEnumerable<T> is sorted? I have an enumerable that I want to verify is sorted in non-descending order, but I can't seem to find native support fo...
Olecranon asked 5/11, 2013 at 9:55
1
Solved
Let's assume we have these 3 classes:
Class BaseClass : System.IComparable
{
[int] $Value
BaseClass([int] $v)
{
$this.Value = $v
}
[int] CompareTo($that)
{
If (-Not($that -is [BaseClass]))...
Canopus asked 6/5, 2018 at 19:26
1
Solved
The documentation for ValueTuple.IComparable.CompareTo(Object) says it returns:
0 if other is a ValueTuple instance; otherwise, 1 if other is null.
This makes the IComparable implementation se...
Durr asked 13/2, 2018 at 11:12
8
Solved
How do I compare values of generic types?
I have reduced it to a minimal sample:
public class Foo<T> where T : IComparable
{
private T _minimumValue = default(T);
public bool IsInRange(T...
Estray asked 25/6, 2011 at 21:16
6
Solved
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.
Weaver asked 12/1, 2009 at 13:33
8
Solved
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?
Guajardo asked 11/2, 2009 at 18:20
1
Solved
I have implemented a very simple binarySearch implementation in C# for finding integers in an integer array:
Binary Search
static int binarySearch(int[] arr, int i)
{
int low = 0, high = arr.Len...
Underwent asked 8/8, 2016 at 20:40
4
Solved
I know that there is a big difference between IComparable and IComparable<T> in general, see this, but in this search method it will not make any difference, or will it?
public static int Se...
Trinette asked 12/12, 2015 at 17:21
3
Solved
I have a class Foo which contains a list of objects: List<Bar>. Each Bar has a property which they can be ordered on (of type TimeSpan, representing a duration), and Bar is an immutable objec...
Calvaria asked 23/7, 2015 at 13:37
1
Solved
I'm making an interval collection extension of the famous C# library C5. The IInterval interface defines an interval with comparable endpoints (irrelevant members removed):
public interface IInter...
Layard asked 16/7, 2015 at 5:0
2
Solved
How would an IComparer that needs an argument be implemented (might not be relevant but I'm using it on Linq query)?
I suppose it should be called like this:
ListOfObjectsToSort.orderBy(x => x...
Striper asked 29/1, 2015 at 22:11
1
I have a C# function that accepts an array of IComparable
public static void sort(IComparable[] a){//...}
If I send an array of strings to this function it is accepted, but an array of ints is ...
Thorbert asked 29/1, 2015 at 15:17
3
Solved
I was doing some statistical operations in C# (.Net 4) with double[] then i found some strange behavior with CompareTo method and double.NaN. when I try this code:
double.NaN.CompareTo(double.Nega...
Ashelyashen asked 21/1, 2013 at 19:26
1
Solved
This code executes successfully in .NET 4.0
public void CompareTest()
{
var m1 = new Foo { Order = 1 };
var m2 = new Foo { Order = 2 };
var c1 = new Bar { Order = -1 };
var c2 = new Bar { Or...
Penrose asked 7/7, 2014 at 12:46
1
Solved
In answering this question, I discovered the following behaviour of compare on discriminated unions.
type T = A | B | C | D
compare A B (* val it : int = -1 *)
compare A C (* val it : int = -2 *...
Pecten asked 14/3, 2014 at 22:52
2
Solved
Let's say I have a type that implements IComparable.
I would have thought it's reasonable to expect that the operators ==, !=, >, <, >= and <= would "just work" automatically by callin...
Mellifluous asked 15/12, 2013 at 11:1
2
Solved
My problem, in a nutshell, is this:
What can I do about storing a tuple (or any type with a constraint of 'comparison') in a C# container that requires an IComparable?
This works:
> let x (y ...
Datnow asked 6/8, 2013 at 22:53
1
Solved
I'm trying to sort a list of objects using List.Sort(), but at runtime it tells me that it cannot compare elements in the array.
Failed to compare two elements in the array
Class structure:
...
Galvanoscope asked 15/5, 2013 at 11:35
1 Next >
© 2022 - 2024 — McMap. All rights reserved.