Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 489721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T01:50:12+00:00 2026-05-13T01:50:12+00:00

I have a IQueryable which is ordered by some condition. Now I want to

  • 0

I have a IQueryable which is ordered by some condition.
Now I want to know the position of a particular element in that IQueryable.
Is there a linq expression to get that.
Say for example there are 10 elements in the IQueryable and the 6th element matches a condition, I want to get the number 6.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T01:50:13+00:00Added an answer on May 13, 2026 at 1:50 am

    First select each item with its index, then filter the items, and finally extract the original index:

    var result = orderedList
        .Select((x, i) => new { Item = x, Index = i })
        .Where(itemWithIndex => itemWithIndex.Item.StartsWith("g"))
        .FirstOrDefault();
    
    int index= -1;
    if (result != null)
        index = result.Index;
    

    Test bed:

    class Program
    {
        static void Main(string[] args)
        {
            var orderedList = new List<string>
            {
                "foo", "bar", "baz", "qux", "quux",
                "corge", "grault", "garply", "waldo",
                "fred", "plugh", "xyzzy", "thud"
            }.OrderBy(x => x);
    
            // bar, baz, corge, foo, fred, garply, grault,
            // plugh, quux, qux, thud, waldo, xyzzy
            // Find the index of the first element beginning with 'g'.
    
            var result = orderedList
                .Select((x, i) => new { Item = x, Index = i })
                .Where(itemWithIndex => itemWithIndex.Item.StartsWith("g"))
                .FirstOrDefault();
    
            int index= -1;
            if (result != null)
                index = result.Index;
    
            Console.WriteLine("Index: " + index);
        }
    }
    

    Output:

    Index: 5
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a huge IQueryable that I want to export directly to Excel for
I have a Linq query that returns an object of the type IQueryable<ClassX> .
I have IQueryable list of objects of type T which I want to transform
I have a IQueryable<Journey> that i collect from my entity model. I want to
I have an LINQ-to-SQL (IQueryable) query, which I need to debug as it's horrendously
I have a IQueryable<SomePOCO> (a LINQ-Entities query, if that matters): public class SomePOCO {
I have a Menu class that has a IQueryable property called WebPages. In the
I have some problem with my code public IQueryable<PageItems> GetPageById(Guid Id) { var xml
So I have this linq query clause. var ctx = new Context(); IQueryable<Users> consulta
I have an IQueryable (PartHistories) that will return a set of objects. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.