[C#] Collection과 Interface
using System; using System.Collections.Generic; clss Program { static void Main() { List c1 = new List(); c1.Add(10); c1.Add(20); c1.Clear(); int n = c1[0]; // IList에 있는 메소드(인덱서) SortedSet c2 = new SortedSet(); c2.Add(10); c2.Add(20); c2.Clear(); int n2 = c2[0]; // error } } 위의 코드에서 List는 동적배열이고 SortedSet은 트리구조이다. 분명 내부적으로 데이터를 다루는 코드는 다를텐데 요소를 추가하는 메소드는 Add로 같다. 또한 모든 요소를 지우는 Clear메소드도 같다. 다른 구..
Study/Language
2021. 11. 15. 15:09