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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:38:29+00:00 2026-06-08T02:38:29+00:00

The language specifics: C# .NET 3.5/4.0; project is meant to be a pre-compiled DLL,

  • 0

The language specifics: C# .NET 3.5/4.0; project is meant to be a pre-compiled DLL, a ‘module’ called/used by other products.

My question is about overall efficiency, and I realize this may come down to a “memory usage vs. CPU cycles” decision, which is fine — I still want to know what you’d consider the better route.

I have a List of MyObjects passed into a method, and the method needs to Sort the List by Property2, do “some stuff” with it, then Sort the List by Property1 to do “something else” & continue with life. Important: the List is already ordered by Property1 when it first comes in to the method (say, from the data layer).

The Sorts will both be “custom inline”, like so:

myList.Sort((ObjA, ObjB) => ObjA.Prop2.CompareTo(ObjB.Prop2));

Is doing the two Sorts a good idea? Or, would it be better to Clone the List to a new ListB, and only call Sort once (on ListB, by Prop2)? Then do “some stuff” with it, and when done, use original List for the “something else” & continue on.

My initial guess is that “Two Sorts” would spin more CPU cycles, whereas “Clone & Sort” would use more memory (since it has to create the new ListB object) — and yes I know that the List members (MyObjects) would not be cloned, they’d just be pointed-at by the new ListB.

Thoughts?

  • 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-06-08T02:38:30+00:00Added an answer on June 8, 2026 at 2:38 am

    Making a new List<T> will be an O(n) operation, as each item will get copied into the new list. List<T>.Sort is typically O(n log n).

    As such, sorting twice will be slower. Copying will require a copy of your list. It’s a memory vs. speed trade off here.

    That being said, copying won’t change the sort order of the original list – this is a large advantage, in my opinion, as passing a list to a method and having it come back changed is often a source of bugs later, as people don’t necessarily expect a method to mutate your ordering. This is especially true as your list is already sorted – if you went to the trouble of creating an ordered list, I would recommend avoiding changing that order if possible.

    However, depending on what you’re doing, you could just use Enumerable.OrderBy to pull out the second set in order, and do your “stuff”. This also has the same advantage as the copy in that it doesn’t change the ordering of the original list.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is kind of more generic question, isn't language-specific. More about idea and algorithm
I'm generating output for a .Net executable from my own language... the opcode (called
I have a .Net 4.0 project called BasicTestProject and it contains a webform called
Question over here is are design patterns specific to a programming language or technology,
Question Is there a mechanism in the .NET Framework to hide one custom Type
I just started a new project, and now with ASP.NET MVC being designed in
In an ASP.NET web forms project that is not quite ready to be upgraded
Recently, my team converted ASP.NET project from .NET 1.1 to .NET 2.0. Everything is
SO I have a HUGE C#/ASP.NET application that is now getting re-appropriated for other
(this is related to this other question ) If you define an Interface where

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.