# IS there a not greater than lambda statement? RSS

## 11 replies

Last post Jun 15, 2012 02:34 AM by Decker Dong - MSFT

Participant

1465 Points

1145 Posts

### IS there a not greater than lambda statement?

I need to filter, so I retrieve one model from a list where a field is equalto or greater than, but not more than, but I carn't figure out the not more than

.Where(v => v.Field >= 35).Where(v => v. not greater than 35)?

Any suggestions would be appriciated

All-Star

86555 Points

9624 Posts

Moderator

MVP

### Re: IS there a not greater than lambda statement?

.Where(x => x.Field >= 35 && x.Field <= 70);

Darrell Norton, MVP
Darrell Norton's Blog

All-Star

27434 Points

4891 Posts

MVP

### Re: IS there a not greater than lambda statement?

Well, if the value is greater than or equal to 35, then it's 35 or higher, right? And then on top of that you want to restrict it to not more than 35? I feel like one of us is missing something. Do you have a specific example? Or do you just mean equals?

.Where(v => v.Field == 35)?

Brock Allen | http://brockallen.com
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/

Participant

1465 Points

1145 Posts

### Re: IS there a not greater than lambda statement?

lets say I have a table called numbers which has an ID field and a numbers field

id   number

1       10

2       20

3      30

4     40

5     50

and so on

all I have is 1 number 35, and I only want to return 1 record, the record which is closest but not over 35

All-Star

27434 Points

4891 Posts

MVP

### Re: IS there a not greater than lambda statement?

Oh yea, I had something like this recently... so do the where and also an orderby and then take the first result:

.Where(x => x.Number <= 35).OrderByDescending(x=>x.Number).First()

I think this logic is right -- actually it's prolly not right but I think you get the idea :)

Brock Allen | http://brockallen.com
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/

Participant

1465 Points

1145 Posts

### Re: IS there a not greater than lambda statement?

Hi

I did think of that, but that seems like a lot of work and wondered it it was more efficitent to do

.Where(x => x.Number <= 35).Where(x => x.Number > 35 - 1).FirstOrDefault()

or another way to do it

• ### Decker Dong ...

All-Star

118619 Points

18779 Posts

EnenDaveyBoy

Hey：）

I think

### BrockAllen

is right……He has given you a full solution；

#### EnenDaveyBoy

.Where(x => x.Number <= 35).Where(x => x.Number > 35 - 1).FirstOrDefault()

Your logic of the codes is hard for me to understand……your first where will gain number smaller or equal to 35，but your 2nd will filter all the numbers larger than 34……；So if your numbers are integer，I don't think you can find a number which is smaller or equal to 35，but larger than 34？

Kindly correct me if I take you wrong……

Reguards！

Participant

1465 Points

1145 Posts

EnenDaveyBoy

Hey：）

I think

### BrockAllen

is right……He has given you a full solution；

#### EnenDaveyBoy

.Where(x => x.Number <= 35).Where(x => x.Number > 35 - 1).FirstOrDefault()

Your logic of the codes is hard for me to understand……your first where will gain number smaller or equal to 35，but your 2nd will filter all the numbers larger than 34……；So if your numbers are integer，I don't think you can find a number which is smaller or equal to 35，but larger than 34？

Kindly correct me if I take you wrong……

Reguards！

Sorry I ment

.Where(x => x.Field >= 35 && x.Field < 35+1);

• ### Decker Dong ...

All-Star

118619 Points

18779 Posts

### Re: IS there a not greater than lambda statement?

#### EnenDaveyBoy

.Where(x => x.Field >= 35 && x.Field < 35+1);

OK:-)

You see，suppose you have a list of numbers：10,15,20,15,30,35,40,45

But

### BrockAllen

is also right！

:D

Participant

1465 Points

1145 Posts