언어 정리 22

C# - StringBulider

주된 사용 이유 -> 반복적인 문자열 수정의 경우 효과적이다 기존방식으로 새로운 문자열을 만들기 string a = "A" string b = "b" string New = a + b; 위 방식으로 저장되면 A, b, Ab모두 메모리에 계속 남아 있는다 새로운 방식 StringBuilder //new StringBulider("heelo", 10) 처음에 용량 지정 및 할당 가능 //용량은 동적으로 조정이 된다 StringBuilder sb = new StringBuilder(); sb.Append("a"); sb.Append("b"); //sb.Insert(1,"K"); //aKb //sb.Replace("b","bbbbb"); // aKbbbbb //sb.Remove(3,2);// akbbb //sb..

언어 정리/c# 2023.12.29

c# - lambda 간단한 사용예제

delegate를 이용한 예제 class MainClass { static void TestLambda(string str){ Console.WriteLine(str); } static void Main() { //delegate에서 사용예 Action test = (string str) => {Console.WriteLine(str);}; test("람다 함수 방식"); TestLambda("함수 선언 방식"); } } linq를 활용한 박씨 이름을 가지고있는 사람들 찾기 class AboutMe{ public string name; public int age; } class MainClass { static void Main() { List MyList = new List(){ new AboutMe ..

언어 정리/c# 2023.11.26

C# - delegate 확장 Func, Action

delegate 는 이미 c#에 잘 정의 되어있어 Func나 Action을 주로사용한다 Func와 Action을 사용하기 전에 어떻게 구성되어있는지 먼저 확인하자 class MainClass { delegate Return Test(T num); static void TestProgram(Test test){ test(1); } static void Main() { //일회성 함수로 람다식을 사용하였다 Test test = (int num) => {Console.WriteLine($"Finish{num}"); return 0;}; TestProgram(test); } } 위와같이 정의한 Test delegate는 미리 정의 되어있는 Func로 아래와 같이 바꿀 수 있다 class MainClass { s..

언어 정리/c# 2023.11.26

c# - delegate 사용법

delegate는 아래와 같이 형식의 이름, 반환값, 입력 값들을 정해준뒤 형식의 이름을 통해 함수를 인자로 넘겨줄 수 있게 만든다 using System; using System.Collections.Generic; using System.Linq; class MainClass { //형식 이름 : TestDelegate //반환값 int //입력 void delegate int TestDelegate(); static void TestProgram(TestDelegate test){ test(); } static int DelegateTest(){ Console.WriteLine("TestFinished"); return 0; } static void Main() { TestProgram(Delega..

언어 정리/c# 2023.11.26

c# - delegate

c++에서 함수포인터와 유사한 delegate(대리자)를 간단한 사용법을 통해 알아보자 1. delegate 선언 //delegate 반환형식 이름(사용할 매개변수) delegate int TestDelegate(int item); 2. delegate 사용 예제 //delegate 선언 delegate void SayWhat(); //Hello 출력함수 static void Hello(){ Console.WriteLine("Hello"); } //Bonjour 출력함수 static void Bonjour(){ Console.WriteLine("Bonjour"); } //delegate사용예제 static void IWantToSay(SayWhat say){ say(); } static void Main..

언어 정리/c# 2023.01.11

c# 문자열 정리

name = name + "추가할 문자열" name.Contains("찾을 단어") //있으면 true name.IndexOf('찾을 문자') //있으면 index 반환 name.ToUpper() // 대문자로 변환 name.ToLower() // 소문자로 변환 name.Replace('변경할 문자', '변경되는 문자') name.Split(delimiterChars, System.StringSplitOptions.RemoveEmptyEntries); // 공백 문자열과 delimiterChars에 있는 문자들을 전부 제거해 준다 name.Substring(위치, 개수) // 위치부터 개수만큼 문자열을 반환한다

언어 정리/c# 2022.12.31

c++ 연산자 우선순위

우선순위 연산자 설명 결합방향 1 :: 범위 지정 연산자 - 2 ++ 후위 증가 연산자 왼쪽에서 오른쪽으로 -- 후위 감소 연산자 왼쪽에서 오른쪽으로 () 함수 호출 왼쪽에서 오른쪽으로 [] 첨자 연산자 왼쪽에서 오른쪽으로 . 멤버 연산자 왼쪽에서 오른쪽으로 -> 멤버 접근 연산자 왼쪽에서 오른쪽으로 typeid 타입 인식 왼쪽에서 오른쪽으로 const_cast 상수 타입 변환 왼쪽에서 오른쪽으로 dynamic_cast 동적 타입 변환 왼쪽에서 오른쪽으로 reinterpret_cast 재해석 타입 변환 왼쪽에서 오른쪽으로 static_cast 정적 타입 변환 왼쪽에서 오른쪽으로 3 ! 논리 NOT 연산자 오른쪽에서 왼쪽으로 ~ 비트 NOT 연산자 오른쪽에서 왼쪽으로 + 양의 부호 (단항 연산자) 오른쪽에..

언어 정리/c++ 2022.11.16