Click here to Skip to main content
15,885,933 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Student table

ID


1

2

3

4

ı want to select student where ıd=3.

How to where condition lambda expression in c#?

What I have tried:

Select(t=>Student).where(x=>x.ID==3)
Posted
Updated 3-Sep-19 9:59am
Comments
Afzaal Ahmad Zeeshan 3-Sep-19 15:05pm    
And the problem is?
ZurdoDev 3-Sep-19 15:12pm    
And the question is?

1 solution

Try:
C#
var selected = studentsCollection.Where(s => s.ID == 3);

or
C#
Student justTheOne = studentsCollection.Where(s => s.ID == 3).FirstOrDefault();
 
Share this answer
 
Comments
George Swan 4-Sep-19 14:31pm    
You don't actually need a 'Where' statement at all, you can do this:
Student justTheOne = studentsCollection.FirstOrDefault(s => s.ID == 3);
OriginalGriff 4-Sep-19 15:53pm    
Yeah - but he's a student and specifically mentioned Where, so it's probably part of the homework exercise.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900