![[C#] 15일차 - 107. IComparable 인터페이스를 이용한 객체의 정렬](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FvuUiB%2FbtqWXalRQFT%2FKV2V9QcKA5l9vBW9xcVBNk%2Fimg.png)
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace A107_IComparable { class Program { static void Main(string[] args) { // Artists객체의 배열 famousArtists를 생성합니다. 생성자 메소드사용 Artists[] famousArtists = { new Artists("레오나르도 다빈치","이탈리아",1452, 1519), new Artists("빈센트 반 고흐","네덜란드",1853, 1890), new Artists("..
![[C#] 15일차 - 106. 두 개의 배열을 쌍으로 정렬](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FuAglO%2FbtqWX5EBzVe%2Fwes5101UUS7mbOYkT9OKH0%2Fimg.png)
Sort(Array, Array);// (1) Sort(Array, Array, IComparer);// (2) Sort(Array, Array, Int32, Int32);// (3) Sort(Array, Array, Int32, Int32, IComparer);// (4) (1) : 앞에 있는 배열을 기준으로 두 개의 배열을 오름차순 정렬합니다. 정렬 기준은 첫번째 배열의 값이고 두번째 배열은 첫번째 배열의 정렬 순서에 따라 정렬됩니다. (2) : (1)번과 같이 정렬하지만 IComparer에 의해 순서가 결정됩니다. (3), (4) : 배열의 전체가 아닌, 배렬의 일부를 정렬할 때 사용됩니다. using System; using System.Collections; using System.Linq; u..
![[C#] 15일차 - 105. 배열을 내림차순으로 정렬하는 방법](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FDeDbe%2FbtqXb1HRTkE%2FxrYMvPK6gPYL6zdr9FzYrK%2Fimg.png)
1. 오름차순으로 정렬 후 내용을 뒤집으면 된다. int[] arr = {12, 32, 43, 24, 8}; Array.Sort(arr);// 오름차순으로 정렬 Array.Reverse(arr); // 배열의 내용을 뒤집어줌 2. Sort() 메소드의 IComparer 인터페이스를 구현해준다. using System; using System.Collections; using System.Linq; using System.Text; using System.Threading.Tasks; namespace A105_IComparer { public class ReverseComparer : IComparer { public int Compare(object x, object y) { string s1 = (s..
![[C#] 15일차 - 104. List<T>와 배열의 정렬](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FcztNu6%2FbtqW8GDW2Gq%2Ff8oK692WBWHNK87obHOPl1%2Fimg.png)
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace A104_AlphabeticalSort { class Program { static void Main(string[] args) { List lstNames = new List(); lstNames.Add("dog"); lstNames.Add("cow"); lstNames.Add("rabbit"); lstNames.Add("goat"); lstNames.Add("sheep"); lstNames.Sort(); foreach (string s in lstNames) Console.Wri..
![[C#] 15일차 - 103. List<T> 컬렉션](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FDDxsh%2FbtqWXbE1Sg7%2F0rpaDLYJE2BhlSqMzr5TI0%2Fimg.png)
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace A103_List { class Program { static void Main(string[] args) { List a = new List(); Random r = new Random(); PrintValues(a); for (int i = 0; i < 10; i++) a.Add(r.Next(100)); PrintValues(a); a.Sort(); PrintValues(a); a.RemoveAt(3); PrintValues(a); } private static void Prin..