如何在scala中将列表转换为队列

时间:2017-11-03 16:18:20

标签: scala list queue

我试过了:

namespace someProgram
{
    public partial class formManage : Form
    {
        private readonly XmlSerializer xs;
        private AddressBook ls;
        private int _counter = 0;
        private string currentFileName;
        public string title { get; set; }
        int selectedRow;
        private static Random random = new Random();

        public formManage()
        {
            InitializeComponent();

            ls = new AddressBook();
            xs = new XmlSerializer(typeof(AddressBook));
            currentFileName = "";
        }

        public void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var saveFileDialog = new SaveFileDialog();
            saveFileDialog.RestoreDirectory = true;
            saveFileDialog.Title = "Select save location file name";
            saveFileDialog.Filter = "XML-File | *.xml";
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                StreamWriter writer = new StreamWriter(saveFileDialog.FileName)

                    SaveFile(writer);

            }
        }

        public void SaveFile(StreamWriter writer)
        {
            foreach (var item in ls.Contacts)
            {
                item.Question1 = XMLEncryption.Model.Helpers.Encryptor.Encrypt(item.Question1);
                item.Question2 = XMLEncryption.Model.Helpers.Encryptor.Encrypt(item.Question2);
                item.Question3 = XMLEncryption.Model.Helpers.Encryptor.Encrypt(item.Question3);
            }
            xs.Serialize(writer, ls);
            MessageBox.Show("File saved... ");
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            selectedRow = e.RowIndex;
            if (selectedRow >= 0)
            {
                buttonUpdate.Enabled = true;
                DataGridViewRow row = dataGridView1.Rows[selectedRow];

                if (dataGridView1.SelectedRows.Count > 0)
                {
                    string question1 = dataGridView1.SelectedRows[0].Cells[4].Value + string.Empty;
                    string question2 = dataGridView1.SelectedRows[0].Cells[6].Value + string.Empty;
                    string question3 = dataGridView1.SelectedRows[0].Cells[8].Value + string.Empty;

                    textBoxQuestion1.Text = question1;
                    textBoxQuestion2.Text = question2;
                    textBoxQuestion3.Text = question3;
                }
            }
        }
    }
}

如果列表中包含元素,请说:列表(1,2,3,4,5)

我想要一个与列表具有相同元素的队列,例如:Queue(1,2,3,4,5)。 但我得到的是:队列(列表(1,2,3,4,5))

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

将列表作为vararg传递:

val myList = List(1, 2, 3, 4, 5)

val myQueue = scala.collection.mutable.Queue(myList: _*)
// Queue(1, 2, 3, 4, 5)