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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:29:29+00:00 2026-05-25T06:29:29+00:00

Possible Duplicate: Remove duplicates from a List<T> in C# i have a List like

  • 0

Possible Duplicate:
Remove duplicates from a List<T> in C#

i have a List like below (so big email list):
source list :

item 0 : jumper@yahoo.com|32432  
item 1 : goodzila@yahoo.com|32432|test23  
item 2 : alibaba@yahoo.com|32432|test65  
item 3 : blabla@yahoo.com|32432|test32 

the important part of each item is email address and the other parts(separated with pipes are not important) but i want to keep them in final list.
as i said my list is to big and i think it’s not recommended to use another list.

how can i remove duplicate emails (entire item) form that list without using LINQ ?
my codes are like below :

private void WorkOnFile(UploadedFile file, string filePath)
{
    File.SetAttributes(filePath, FileAttributes.Archive);

    FileSecurity fSecurity = File.GetAccessControl(filePath);
    fSecurity.AddAccessRule(new FileSystemAccessRule(@"Everyone",
                                                    FileSystemRights.FullControl,
                                                    AccessControlType.Allow));
    File.SetAccessControl(filePath, fSecurity);

    string[] lines = File.ReadAllLines(filePath);
    List<string> list_lines = new List<string>(lines);
    var new_lines = list_lines.Select(line => string.Join("|", line.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries)));
    List<string> new_list_lines = new List<string>(new_lines);
    int Duplicate_Count = 0;
    RemoveDuplicates(ref new_list_lines, ref Duplicate_Count);
    File.WriteAllLines(filePath, new_list_lines.ToArray());
}

private void RemoveDuplicates(ref List<string> list_lines, ref int Duplicate_Count)
{
    char[] splitter = { '|' };
    list_lines.ForEach(delegate(string line)
    {
        // ??
    });
}

EDIT :
some duplicate email addrresses in that list have different parts ->
what can i do about them :
mean

goodzila@yahoo.com|32432|test23   
and   
goodzila@yahoo.com|asdsa|324234

Thanks in advance.

  • 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-25T06:29:30+00:00Added an answer on May 25, 2026 at 6:29 am
    private void RemoveDuplicates(ref List<string> list_lines, ref int Duplicate_Count)
    {
        Duplicate_Count = 0;
        List<string> list_lines2 = new List<string>();
        HashSet<string> hash = new HashSet<string>();
    
        foreach (string line in list_lines)
        {
            string[] split = line.Split('|');
            string firstPart = split.Length > 0 ? split[0] : string.Empty;
    
            if (hash.Add(firstPart)) 
            {
                list_lines2.Add(line);
            }
            else
            {
                Duplicate_Count++;
            }
        }
    
        list_lines = list_lines2;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Remove duplicates from array I have a list of items. I want
Possible Duplicate: How to remove elements from an array I have an List with
Possible Duplicate: Can you remove elements from a std::list while iterating through it? I
Possible Duplicate: Can you remove elements from a std::list while iterating through it? I
Possible Duplicate: Unwanted margin in inline-block list items How to remove Invisible space from
Possible Duplicate: How do you send email from a Java app using Gmail? How
Possible Duplicate: C# Cannot convert from IEnumerable<Base> to IEnumerable<Derived> I have D1 and D2
I'm having issues finding the most efficient way to remove duplicates from a list
Possible Duplicate: How do I remove diacritics (accents) from a string in .NET? I
Possible Duplicate: How to remove duplicate values from an array in PHP How can

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.