Programming Language/이것이 C# 연습문제 풀이
이것이 C# 13장 연습문제 풀이
dbxxrud
2019. 12. 19. 19:51
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
27
28
29
30
31
32
33
34
35
|
using System;
using System.Collections;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using System.IO;
namespace Practice2
{
delegate int MyDelegate(int a, int b); // 익명메소드 선언
class MainApp
{
static void Main(string[] args)
{
MyDelegate Callback;
Callback = delegate (int a, int b)
{
return a + b;
};
WriteLine(Callback(3, 4));
Callback = delegate (int a, int b)
{
return a - b;
};
WriteLine(Callback(7, 5));
}
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs |
2번 문제
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;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using System.IO;
namespace Practice2
{
delegate void MyDelegate(int a); // 익명메소드 선언
class Market
{
public event MyDelegate CustomerEvent;
public void BuySomething(int CustomerNo)
{
if (CustomerNo == 30)
CustomerEvent(CustomerNo);
}
}
class MainApp
{
static public void MyEvent(int a)
{
WriteLine("축하! {0}번째 고객 이벤트에 당첨!", a);
}
static void Main(string[] args)
{
Market market = new Market();
market.CustomerEvent += new MyDelegate(MyEvent);
for (var customerNo = 0; customerNo < 100; customerNo += 10)
market.BuySomething(customerNo);
}
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs |