Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

sort list

Posted on 2011-03-14
6
Medium Priority
?
231 Views
Last Modified: 2012-05-11
Hello, I have a list(double type). I want to know if all items are greater than 1 or less than 1 at the same time, then a flag is raised.
For ex,
0.7776
0.8121
1.27

Open in new window

Some are <1, the other >1. than I got false.
0.3492
0.3945

Open in new window

I should get a true.
Thanks.
0
Comment
Question by:zhshqzyc
  • 3
  • 2
6 Comments
 
LVL 22

Expert Comment

by:p_davis
ID: 35130462
bool greaterThanOne = yourList.Exists(num=>num > 1);
0
 
LVL 22

Expert Comment

by:p_davis
ID: 35130474
sorry it should be reversed.


bool greaterThanOne = !yourList.Exists(num=>num > 1);
0
 

Author Comment

by:zhshqzyc
ID: 35130578
NO, YOU MISUNDERSTOOD MY QUESTION.
I mean if all great than 1 or all less than 1. I shou get true. The data go the the same direction, towards to >1 or <1.
If mixed direction then get false.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 248 total points
ID: 35130583
I think it'd be more along the lines of (take note that there is only 1 ampersand):

bool result = theList.Any(item => item > 1) & theList.Any(item => item < 1);

Open in new window

0
 
LVL 22

Assisted Solution

by:p_davis
p_davis earned 252 total points
ID: 35130595
bool same = !yourList.Exists(num=> num < 1 && num > 1);
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35130599
In light of the recent post, modify it to this:
bool result = !(theList.Any(item => item > 1) & theList.Any(item => item < 1));

Open in new window

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question