반응형
큐, 스택, 리스트 객체들을 바꾸는 것이 가능합니다.
복사하려는 컬렉션을 매개변수로 받아들이는 생성자를 쓰기만 하면 됩니다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace QueStackCopy
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void CopyButton_Click(object sender, EventArgs e)
{
Stack<string> myStack = new Stack<string>();
myStack.Push("첫번 째 줄");
myStack.Push("두번 째 줄");
myStack.Push("세번 째 줄");
myStack.Push("마지막 줄");
//복사
Queue<string> myQueue = new Queue<string>(myStack);
List<string> myList = new List<string>(myStack);
Stack<string> anotherStack = new Stack<string>(myList);
MessageBox.Show("myQueue has " + myQueue.Count + "items \n"
+ "mtList has " + myList.Count + "items \n"
+ "anotherStack has " + anotherStack.Count + "items \n");
}
}
}
|
cs |
728x90
반응형