Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Create your online store today with Shopify

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Disclosure: My content contains affiliate links.

43,235 questions

56,137 answers

573 users

How to remove duplicates from string array in C#

2 Answers

0 votes
using System;
using System.Linq;

class Program
{
    static void Main() {
        string[] arr = { "c#", "c#", "c", "c++", "php", "c", "c", "java" };
        arr = arr.Distinct().ToArray();

        Array.ForEach(arr, s => Console.WriteLine(s));
    }
}



/*
run:

c#
c
c++
php
java

*/

 



answered Sep 22, 2020 by avibootz
0 votes
using System;
using System.Linq;
using System.Collections.Generic;
 
class Program
{
    static void Main() {
        string[] arr = { "c#", "c#", "c", "c++", "php", "c", "c", "java" };

        var hash = new HashSet<string>(arr);
        
        arr = hash.ToArray();
        
        Console.WriteLine(string.Join(", ", arr));
    }
}
 
 
 
/*
run:
 
c#, c, c++, php, java
 
*/

 



answered Jul 18, 2022 by avibootz

Related questions

1 answer 192 views
1 answer 120 views
2 answers 242 views
242 views asked Mar 19, 2023 by avibootz
1 answer 175 views
1 answer 272 views
...