0

I want order to object array by one of its variables "n_common" and this gives me error:

you can´t convert Lambda expressions in the type array because is not a type delegate.

cartesian_product.Sort((a, b) => -1 * a.n_common.CompareTo(b.n_common));

I want to order descending my "Pair" object that contains 3 variable "p", "q" and "n_common", it should be ordered by the "n_common", the cartesian_product is a array of Pair object.

I am not working with Linq just with Lambda expression or at least that is how I understand it anyway I put the linq in the header and the problem continues

2
  • No because I am not working with Linq just with Lambda expression or at least that is how I understand it anyway I put the linq in the header and the problem continues Commented Mar 10, 2019 at 22:43
  • What is the type of cartisian_product? What do you expect your lambda to do. I believe that Sort is expecting a delegate that takes an instance of the type the collection is collecting and return a value that can be sorted. Something like people.Sort(p => p.Age) would take a collection of persons (in a variable people and sort them by age. In your case, the delegate is specifying a function that takes two parameters). Commented Mar 10, 2019 at 23:18

2 Answers 2

0

Sort is a static method, so it must be called from the class Array not an instance. Try this:

Array.Sort(cartesian_product, (a, b) => -1 * a.n_common.CompareTo(b.n_common));
Sign up to request clarification or add additional context in comments.

Comments

0

At the top of your class add using System.Linq; and using System.Data.Entity;.

2 Comments

No because I am not working with Linq just with Lambda expression or at least that is how I understand it anyway I put the linq in the header and the problem continues
The various extension methods that take a lambda expression (for example Sort) are defined in System.Linq. You may not think you are using LINQ, but you are.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.