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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:29:14+00:00 2026-05-24T23:29:14+00:00

I need a list of unique values. But it could be, the values exists

  • 0

I need a list of unique values. But it could be, the values exists twice or more in the list.
If this occurs I must rename the value but the renamed value also could be in the list.

It is possible to rename the values using a LINQ query so i don’t need a sub-query?

example 1:
before:
“one”, “one”, “two”, “two”, “three”
after:
“one”, “one_”, “two”, “two_”, “three”

example 2:
before:
“one”, “one”, “one_”
after:
“one”, “one_”, “one__”

The 3rd “one” has 2 underscores because the 2nd “one” was renamed to “one_”.

Thanks a lot for an idea…

  • 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-24T23:29:14+00:00Added an answer on May 24, 2026 at 11:29 pm

    I don’t think this should be done with simply a linq-query. I’d use a HashSet and create a function if I was you. Something like this:

    IEnumerable<String> GetUnique(IEnumerable<String> list) {
        HashSet<String> itms = new HashSet<String>();
        foreach(string itm in list) {
             string itr = itm;
             while(itms.Contains(itr)) {
                 itr = itr + "_";
             }
             itms.Add(itr);
             yield return itr;
        }
    }
    

    [Edit]

    This could be made into an extension-method though, so you could call it like this: myList.GetUnique(); (or something like that)

    [Edit 2]

    Fixed bug with iterator-variable being changed.

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

Sidebar

Related Questions

Given a list I need to return a list of lists of unique items.
I have a list of about a hundreds unique strings in C++, I need
I need to list all files whose names start with 'SomeLongString'. But the case
I'm in this situation that i need a list of lists. for instance i
I have a List<InputField> but I need a List<IDataField> Is there a way to
I need to make a list of key-value pairs (similar to std::map<std::string, std::string> )
I need a list of integers from 1 to x where x is set
I need a list of URLs to apply filters to and at the moment
I need a list from OldGuids that are not in the NewGuids, so I
I often need to list items with various-sized images on the left and text

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.