Language 23

[C#] Orderby

What is Orderby Function?배열이나 리스트의 각 요소에 대해 "정렬 기준"을 하나 설정하고, 그 기준에 맞게 오름차순으로 정렬하는 함수숫자 리스트를 오름차순으로 정렬int[] numbers = {5,2,9,1,6};int[] sorted = numbers.OrderBy(x=>x).ToArray();// 결과=> numbers : {1,2,5,6,9}객체 리스트를 특정 필드를 기준으로 정렬class Person{ public sring Name {get;set;} public int Age{get;set;}}List people = new List{ new Person{Name="Alice", Age = 30}, new Person{Name="Bob", Age = 25}, new Pers..

Language/C# 2024.10.14

[기본] 참조(얕은 복사)

Class Class A{ public B b; } Class B{ public int c; } Class Main{ public main(){ B b = new B(); // B를 메모리에 할당 -> heap의 MB공간을 차지한다고 가정 A a = new A(); // A를 메모리에 할당 -> heap의 MA공간을 차지한다고 가정 a.b = b; // A의 b는 MB를 참조함 } }예제 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(strin..

Language/C# 2022.09.20

[C#문법] Dictionary

초기화 Dictionary dic = new Dictionary(); Dictionary dic = new Dictionary(){{key,value},{key,value}} 값할당 dic[key] = value dic.Add(key,value) foreach foreach(dtype key in dic.Keys){} foreach(dtype value in dic.value){} foreach(KeyValuePair kvp in dic){ Debug.log(kvp.Key); Debug.log(kvp.Value); } 복사 생성자 인수에 복사하고 싶은 오브젝트 지정 var dic2 = new Dictionary(dic); 기능 bool dic.Remove(key) 해당 key,value쌍 제거 dic.R..

Language/C# 2022.08.31