Linq query for top 1

i am trying to retrieve the top 1 object from the following query but it is not working as expected. Please help.
Dim LastQuestion As Question = (From q In qu Order By q.QuestionNumber Descending Take 1 Select q)

Open in new window

suromaAsked:
Who is Participating?
 
nepaluzConnect With a Mentor Commented:
Actually, you probably do not need to define that.
Take 1 means you are looking for and up to position 1, just use .First instead, e.g
Dim LastQuestion As Question = (From q In qu Order By q.QuestionNumber Descending Select q).First

Open in new window

0
 
Kiran SonawaneProject LeadCommented:
Try this


Dim LastQuestion As Question = (From q In qu Order By q.QuestionNumber Descending Select q).Take(1)
0
 
Kiran SonawaneProject LeadCommented:
Sorry it was c# syntax.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
nepaluzCommented:
give us your definition of qu
0
 
nepaluzCommented:
Also your Question has to implement IComparable
0
 
suromaAuthor Commented:
Works perfectly. Many thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.