0

I have this application where i have to insert the same string in a textbox as the one in the array. The strings come by in a label, for every answer it will go to a random word/string that is in the array.

My question is: Is there any way to delete or disable a word/string in the array so I don't get any duplicates?

string[] arrProvincies = File.ReadAllLines(@"provincies.txt");

int counter = 0;
string Array = "";

string Array = arrProvincies[counter].ToString();
lblProvincie.Text = Array;
counter = rnd.Next(0, 12);
Thomas Ayoub
  • 29,063
  • 15
  • 95
  • 142
Gekkehond
  • 128
  • 1
  • 13

2 Answers2

2

You can use a Queue:

Queue<string> arrProvincies = new Queue<string>(File.ReadAllLines(@"provincies.txt"));

And use it with lblProvincie.Text = arrProvincies.Dequeue();

Thus you'll be sure to have no duplicate since your remove the entry when you use it.


If you need shuffling:

Queue<string> arrProvincies = new Queue<string>(File.ReadAllLines(@"provincies.txt").OrderBy(o => Guid.NewGuid()));
Thomas Ayoub
  • 29,063
  • 15
  • 95
  • 142
1
string[] arrProvincies = File.ReadAllLines(@"provincies.txt");

var randomProvincies = arrProvincies.Distinct().OrderBy(i => Guid.NewGuid());

randomProvincies would be the distinct values ordered randomly (I couldn't understand the part where it says you would insert the same string in a textbox).

Cetin Basoz
  • 22,495
  • 3
  • 31
  • 39