-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
106 lines (89 loc) · 2.79 KB
/
Program.cs
File metadata and controls
106 lines (89 loc) · 2.79 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CSInterface32
{
internal class Program
{
class Parent { }
class Child : Parent, IComparable<Child>, IDisposable
{
public int CompareTo(Child other)
{
throw new NotImplementedException();
}
public void Dispose()
{
throw new NotImplementedException();
}
}
class TestClass : IBasic
{
public int TestProperty
{
get { return -1; }
set { int n = value; }
}
public int TestInstanceMethod()
{
// do something
return -1;
}
}
class Dummy : IDisposable
{
public void Dispose()
{
Console.WriteLine("Dispose() 메서드 호출됨");
}
}
class Product : IComparable<Product>
{
public string Name { get; set; }
public int Price { get; set; }
public int CompareTo(Product other)
{
return this.Price.CompareTo(other.Price);
//return this.Name.CompareTo(other.Name);
}
public override string ToString()
{
return Name + " : " + Price;
}
}
static void Main(string[] args)
{
List<Product> products = new List<Product>()
{
new Product() { Name = "감자", Price = 1500 },
new Product() { Name = "고구마", Price = 5000 },
new Product() { Name = "양파", Price = 1400 },
new Product() { Name = "배추", Price = 2300 },
new Product() { Name = "상추", Price = 1300 },
};
products.Sort();
foreach (var item in products)
{
Console.WriteLine(item);
}
using (Dummy dummy = new Dummy())
{
Console.WriteLine("using 블록 안에 들어왔습니다.");
}
Console.WriteLine("using 블록을 벗어났습니다.");
// 다형성의 예 - 다양한 얼굴(역할)을 가졌다!
TestClass tc = new TestClass();
IBasic ib = tc;
IBasic ib2 = new TestClass();
TestClass tc2 = (TestClass)ib2;
TestClass tc3 = (TestClass)ib;
Child child = new Child();
Parent parent = child;
IDisposable childAsDisposable = new Child();
IComparable<Child> childAsComparable = new Child();
}
}
}