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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:18:47+00:00 2026-05-10T16:18:47+00:00

I got a Function that returns a Collection<string> , and that calls itself recursively

  • 0

I got a Function that returns a Collection<string>, and that calls itself recursively to eventually return one big Collection<string>.

Now, i just wonder what the best approach to merge the lists? Collection.CopyTo() only copies to string[], and using a foreach() loop feels like being inefficient. However, since I also want to filter out duplicates, I feel like i’ll end up with a foreach that calls Contains() on the Collection.

I wonder, is there a more efficient way to have a recursive function that returns a list of strings without duplicates? I don’t have to use a Collection, it can be pretty much any suitable data type.

Only exclusion, I’m bound to Visual Studio 2005 and .net 3.0, so no LINQ.

Edit: To clarify: The Function takes a user out of Active Directory, looks at the Direct Reports of the user, and then recursively looks at the direct reports of every user. So the end result is a List of all users that are in the ‘command chain’ of a given user.Since this is executed quite often and at the moment takes 20 Seconds for some users, i’m looking for ways to improve it. Caching the result for 24 Hours is also on my list btw., but I want to see how to improve it before applying caching.

  • 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-10T16:18:48+00:00Added an answer on May 10, 2026 at 4:18 pm

    If you’re using List<> you can use .AddRange to add one list to the other list.

    Or you can use yield return to combine lists on the fly like this:

    public IEnumerable<string> Combine(IEnumerable<string> col1, IEnumerable<string> col2) {     foreach(string item in col1)         yield return item;      foreach(string item in col2)         yield return item; } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 118k
  • Answers 118k
  • 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
  • Editorial Team
    Editorial Team added an answer I like to choose linux distros based on whichever ones… May 11, 2026 at 11:36 pm
  • Editorial Team
    Editorial Team added an answer Sriram Narayan says to String-encode the Key to get it… May 11, 2026 at 11:36 pm
  • Editorial Team
    Editorial Team added an answer Iterator blocks use deferred execution - meaning: until you actually… May 11, 2026 at 11:36 pm

Related Questions

I've got a collection of strings, and I need to know the first index
I've got a bunch of web page content in my database with links like
I'm referencing the article reference To create a UserControl dynamically and pass it back
I've got a function in C#, and I'd like to port it (among some

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.