반응형
뇌를자극하는 C#.md

뇌를 자극하는 C# 5.0 프로그래밍 Chapter11 연습문제


1. 다음 코드에서 문제를 찾고, 그 원인을 설명하세요.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
using System;
using System.Collections;
using System.Collections.Generic;
 
namespace Ex11_1
{
    class MainApp
    {
        static void Main(string[] args)
        {
            Queue queue = new Queue();
            queue.Enqueue(10);
            queue.Enqueue("한글");
            queue.Enqueue(3.14);
 
            Queue<int> queue2 = new Queue<int>();
            queue2.Enqueue(10);
            queue2.Enqueue("한글");
            queue2.Enqueue(3.14);
        }
    }
}
cs


18, 19줄이 문제이다. 16줄 Queue<int> queue2 = new Queue<int>();를 보면 queue2는 형식 매개 변수로 입력한 형식인 int형 외에 입력을 허용하지 않는다. 따라서 queue2에는 int형 외에는 입력할 수 없다.



2. 다음 코드에서 1)에 들어갈 내용은 무엇입니까?

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
using System;
using System.Collections.Generic;
 
namespace Ex11_2
{
    class MainApp
    {
        static void Main(string[] args)
        {
            Dictionary<string,string> dic = new Dictionary<string,string>();
 
            dic["하나"= "one";
            dic["둘"= "two";
            dic["셋"= "three";
            dic["넷"= "four";
            dic["다섯"= "five";
 
            Console.WriteLine(dic["하나"]);
            Console.WriteLine(dic["둘"]);
            Console.WriteLine(dic["셋"]);
            Console.WriteLine(dic["넷"]);
            Console.WriteLine(dic["다섯"]);
        }
    }
}
 
cs

출력결과




반응형

+ Recent posts