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 62499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:29:08+00:00 2026-05-10T18:29:08+00:00

Anyone have a good resource or provide a sample of a natural order sort

  • 0

Anyone have a good resource or provide a sample of a natural order sort in C# for an FileInfo array? I am implementing the IComparer interface in my sorts.

  • 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. 2026-05-10T18:29:08+00:00Added an answer on May 10, 2026 at 6:29 pm

    The easiest thing to do is just P/Invoke the built-in function in Windows, and use it as the comparison function in your IComparer:

    [DllImport('shlwapi.dll', CharSet = CharSet.Unicode)] private static extern int StrCmpLogicalW(string psz1, string psz2); 

    Michael Kaplan has some examples of how this function works here, and the changes that were made for Vista to make it work more intuitively. The plus side of this function is that it will have the same behaviour as the version of Windows it runs on, however this does mean that it differs between versions of Windows so you need to consider whether this is a problem for you.

    So a complete implementation would be something like:

    [SuppressUnmanagedCodeSecurity] internal static class SafeNativeMethods {     [DllImport('shlwapi.dll', CharSet = CharSet.Unicode)]     public static extern int StrCmpLogicalW(string psz1, string psz2); }  public sealed class NaturalStringComparer : IComparer<string> {     public int Compare(string a, string b)     {         return SafeNativeMethods.StrCmpLogicalW(a, b);     } }  public sealed class NaturalFileInfoNameComparer : IComparer<FileInfo> {     public int Compare(FileInfo a, FileInfo b)     {         return SafeNativeMethods.StrCmpLogicalW(a.Name, b.Name);     } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 69k
  • Answers 69k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer You may want to check out Railroad. It takes your… May 11, 2026 at 12:40 pm
  • added an answer I found this PowerShell one-liner script that supposedly lists all… May 11, 2026 at 12:40 pm
  • added an answer On both 32-bit and 64-bit machines: long is 64-bit, it's… May 11, 2026 at 12:40 pm

Related Questions

Anyone have a good rule of thumb for choosing between different implementations of Java
Does anyone have a good way to build MSI (vdproj) projects using MsBuild or
Does anyone have a good solution for integrating some C# code into a java
Does anyone have a good technique (or tutorial) to implement rulers within a C#
I have a mobile platform that I am trying to write some communications code
I am looking for a Repository pattern implementation example/resource that follows domain driven design
I would like to show some hidden text in a Flex application and have
Can anyone recommend a good resource -- book, website, article, etc -- to help

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.