gpt4 book ai didi

c# - 随机化队列

转载 作者:行者123 更新时间:2023-12-03 03:03:49 25 4
gpt4 key购买 nike

我从 txt 文件中读取行。它们大约有 100 000 个。如何填充队列并对其元素进行洗牌?像这样填充队列:

    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();
}
}

最佳答案

队列用于 FIFO。您要求的是 FIFO 之外的其他。因此,您使用了错误的工具来完成这项工作。

一个简单的方法是填充队列,填充列表,然后shuffle the elements of the list,而不是填充队列。 .

关于c# - 随机化队列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17932099/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com