I read lines from txt file. They are about 100 000. How to fill queue and shuffle its elements? Fill queue like this:
Queue<string> accs = new Queue<string>();
private void loadLikeAccountsToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.RestoreDirectory = true;
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
accs.Clear();
foreach (string s in File.ReadAllLines(openFileDialog1.FileName))
{
accs.Enqueue(s);
}
label4.Text = accs.Count.ToString();
}
}
A queue is for FIFO. You're asking for something other than FIFO. So, you're using the wrong tool for the job.
A simple approach is instead of filling a queue, fill a list, and then shuffle the elements of the list.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With