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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:49:18+00:00 2026-05-14T06:49:18+00:00

How to remove duplicates from a StringCollection in c#? I was looking for a

  • 0

How to remove duplicates from a StringCollection in c#? I was looking for a more efficient approach. StringCollection is returned from an API.

  • 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-14T06:49:18+00:00Added an answer on May 14, 2026 at 6:49 am

    Just use a HashSet<string> as your collection, rather than StringCollection. It is designed to prevent the addition of duplicate elements by comparing hash codes of those elements (thus being very efficient).

    Edit: Since it would seem you’re returned a StringCollection in the first place, then the solution should just be to loop over all the items in the StringCollection and add them to a HashSet<string>, thereby eliminating duplicates. The Enumerable.Distinct extension method would also do the job, but less efficiently I suspect, since it does use hashing (rather just normal equality testing). Something like this:

    var noDuplicatesItems = stringCollection.Cast<string>().Distinct().ToArray();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do I remove duplicates from a list, while preserving order? Using a set
I need to remove duplicate rows from a fairly large SQL Server table (i.e.
How can I remove duplicate values from an array in PHP?
I'm putting together a script to find remove duplicates in a large library of
A query that is used to loop through 17 millions records to remove duplicates
I have a list of integers in C#. I wish to remove duplicates. In
Given a list of strings, I want to sort it alphabetically and remove duplicates.
I have an Array of Objects that need the duplicates removed/filtered. I was going
Duplicate of What's the BEST way to remove the time portion of a datetime
After using array_unique , an array without the duplicate values is removed. However, it

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.