0

I am creating similar properties list.

I have to look for the 4 similar range properties in the list.

  • If the price is $400,000 then I have to find 4 properties of $400,000 price.

If the 4 properties could not be found then

  • Sort the list high to low and find the remaining properties from the list.

If there are no same price properties then

  • Sort the list from high to low and get two properties from the list

  • And again sort the list low to high and get the 2 properties from the list

In order to find the same price properties

var properties = props.results.Where(x => x.Price== price).ToList().Take(4); 

High to low list

var highToLow = props.results.OrderByDescending(x => x.Price).ToList().Take(4); 

Low to high list

var lowToHigh = props.results.OrderBy(x => x.Price).ToList().Take(4); 

The problem is

When there is less than 4 properties found from the same price properties

var properties = props.results.Where(x => x.Price== price).ToList().Take(4); 

Now I am sorting the list High to Low and finding rest of the properties from this High to Low list.

var highToLow = props.results.OrderByDescending(x => x.Price).ToList().Take(4); 

How can I combine the list ?

Has anyone done something similar to what I am trying to achieve. Any help or suggestion would be appreciated.

Thanks in advance

2
  • your class structure is needed Commented Feb 5, 2019 at 5:16
  • How can I combine the list ? Concat or Union. Commented Feb 5, 2019 at 5:44

1 Answer 1

1

You need to use Enumerable.Union:

var result= properties.Union(highToLow) 

If your list is a list of objects then you should implement an equality comparer that can be used in the Union method. Enumerable.Union

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.