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

  • Home
  • SEARCH
  • 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 859181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:38:44+00:00 2026-05-15T08:38:44+00:00

Can someone tell me what I’m doing wrong with the following Linq query? I’m

  • 0

Can someone tell me what I’m doing wrong with the following Linq query? I’m trying to find the directory with the highest aphanumerical value.

        DirectoryInfo[] diList = currentDirectory.GetDirectories();

        var dirs = from eachDir in diList
                   orderby eachDir.FullName descending                    
                   select eachDir;
        MessageBox.Show(dirs[0].FullName);

EDIT:

The above code does not compile, the error that the compiler generates is:

Cannot apply indexing with [] to an expression of type 'System.Linq.IOrderedEnumerable<System.IO.DirectoryInfo>
  • 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-15T08:38:45+00:00Added an answer on May 15, 2026 at 8:38 am

    You’re trying to access dirs as if it were an array or a list. It’s just an IEnumerable<T>. Try this:

    var dirs = diList.OrderByDescending(eachDir => eachDir.FullName);
    var first = dirs.FirstOrDefault();
    // Now first will be null if there are no directories, or the first one otherwise
    

    Note that I haven’t used a query expression here because it seems pretty pointless for just a single clause. You could put it all into one statement, too:

    var first = currentDirectory.GetDirectories()
                                .OrderByDescending(eachDir => eachDir.FullName)
                                .FirstOrDefault();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone tell me what i am doing wrong here? I want the boxes
Can someone tell me what I'm doing wrong to package this as a module:
Can someone tell me what is wrong with the following code? Set<String> cmds =
Can someone tell me what I am doing wrong here: function onAjaxDone(data) { var
Can someone tell me what I'm doing wrong here and how to make the
Can someone tell what is wrong with this query? sqltext = SELECT utyp, count(*)
Can someone tell me what I am doing wrong in the View for Dropdownlist?
Can someone tell me why the following does not match: >>> re.search(r'(\d{2, 10})', '153')
Can someone tell me what's wrong with this http://jsfiddle.net/Yp8Bz/ ? It works fine in
Can someone tell me a fast function to find the square of each pixel

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.