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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:28:52+00:00 2026-05-25T13:28:52+00:00

I have an array of strings, f.e. string [] letters = { a, a,

  • 0

I have an array of strings, f.e.

string [] letters = { "a", "a", "b", "c" };

I need to find a way to determine if any string in the array appears more than once.
I thought the best way is to make a new string-array without the string in question and to use Contains,

foreach (string letter in letters)
{
    string [] otherLetters = //?
    if (otherLetters.Contains(letter))
    {
        //etc.     
    }
}

but I cannot figure out how.
If anyone has a solution for this or a better approach, please answer.

  • 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-25T13:28:53+00:00Added an answer on May 25, 2026 at 1:28 pm

    The easiest way is to use GroupBy:

    var lettersWithMultipleOccurences = letters.GroupBy(x => x)
                                               .Where(g => g.Count() > 1)
                                               .Select(g => g.Key);
    

    This will first group your array using the letters as keys. It then returns only those groups with multiple entries and returns the key of these groups. As a result, you will have an IEnumerable<string> containing all letters that occur more than once in the original array. In your sample, this is only “a”.

    Beware: Because LINQ is implemented using deferred execution, enumerating lettersWithMultipleOccurences multiple times, will perform the grouping and filtering multiple times. To avoid this, call ToList() on the result:

    var lettersWithMultipleOccurences = letters.GroupBy(x => x)
                                               .Where(g => g.Count() > 1)
                                               .Select(g => g.Key).
                                               .ToList();
    

    lettersWithMultipleOccurences will now be of type List<string>.

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

Sidebar

Related Questions

Say I have an array of strings: string[] strArray = {aa, bb, xx, cc,
I have an array of strings in python which each string in the array
I have an array of strings plus one additional string. I want to use
I have an array of drive letters and I need to append a colon
I've been trying to find a more pythonic way of generating random string in
I have a string array: string[] authors = new string[3]; authors[0] = Charles Dickens;
I have this array: string[,] productData = new string[5,7]; I bind it to a
An array is defined of assumed elements like I have array like String[] strArray
i have an array below string stringArray = new stringArray[12]; stringArray[0] = 0,1; stringArray[1]
I have an array of strings var controlsToGet = new[] {lblHome,lblContact}; I have List<LanguageControl>

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.