0

I have a list in the below it has 18 value.I have another list(include unique 6 value) created by random numbers(1,18), and they are unique.
When i do these for example elidenkiKartlar list shows me 6 unique values, but i have 2 list more in other lists, I have same values for example in elindekiKartlar=K1,K3,S4,RD-1,S2,M4 in another list K1,K4,RD-2,S4,K3, i have same values (K1,K3) e.g.
How can i remove them ? How can I share this big list to 3 equal(6,6,6) part ?
Thanks for your advise from now..

  public List<string> kartlar = new List<string>
    {
        "S1",
        "S2",
        "S3",
        "S4",
        "S5",
        "M1",
        "M2",
        "M3",
        "M4",
        "M5",
        "K1",
        "K2",
        "K3",
        "K4",
        "K5",
        "RD-1",
        "RD-2",
        "RD-3",
    };

      //Creating uniqe random list

            int [] sayilar=new int[6];

            for (int i = 0; i < sayilar.Length; i++)
            {
                essiz:
                sayilar[i] = random.Next(0, 18);
                for (int j = 0; j < i; j++)
                {
                    if (sayilar[i]==sayilar[j])
                    {
                        goto essiz;
                    }

                }
            }


  //Adding string items by randomList index 

            foreach (var sayi in sayilar)
        {
            elindekiKartlar.Add(kartlar[sayi]);
        }
Mohammed Sajid
  • 4,778
  • 2
  • 15
  • 20
yznmedia
  • 3
  • 3
  • Does this answer your question? [Remove duplicates from a List in C#](https://stackoverflow.com/questions/47752/remove-duplicates-from-a-listt-in-c-sharp) – Pavel Anikhouski May 16 '20 at 12:31

2 Answers2

1

Use Distinct Method

var uniqueValues = kartlar.Distinct().ToList();
Mihir Dave
  • 3,954
  • 1
  • 12
  • 28
  • kartlar ıs a unıqe lıst dıstınct doesnt work.My sımple questıon ıs how can ı share my lıst to 3 uniqe part? – yznmedia May 16 '20 at 14:52
0

Try this

elindekiKartlar.Distinct();
Yargicx
  • 1,704
  • 3
  • 16
  • 36