Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# sort list

Posted on 2011-03-14
Medium Priority
230 Views
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
``````
Some are <1, the other >1. than I got false.
``````0.3492
0.3945
``````
I should get a true.
Thanks.
0
Question by:zhshqzyc
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 3
• 2

LVL 22

Expert Comment

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

LVL 22

Expert Comment

ID: 35130474
sorry it should be reversed.

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

Author Comment

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

LVL 75

Accepted Solution

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);
``````
0

LVL 22

Assisted Solution

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

LVL 75

Expert Comment

ID: 35130599
In light of the recent post, modify it to this:
``````bool result = !(theList.Any(item => item > 1) & theList.Any(item => item < 1));
``````
0

## Featured Post

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
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.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
###### Suggested Courses
Course of the Month9 days, 21 hours left to enroll