목록C# (18)
Game Tech Blog
리플렉션 이란? C# 에서는 어플리케이션 실행 도중에 객체의 정보를 확인하기 위한 기능이다. 객체의 정보는 주로 메서드, 프로퍼티, 생성자등 인스턴스 데이터 타입 정보를 통칭한다. 예를들어, 내가 지금 제네릭 클래스를 원소로 List 등 자료구조를 사용하고 있을때, 내가 A 클래스를 쓰고 있는지 B 클래스를 쓰고 있는지 알 수 없는데, 리플렉션에 있는 GetType() 을 사용하면 내가 현재 쓰고 있는 클래스 형태를 알 수 있다. 그렇다면, 리플렉션은 어떻게 사용되어야 효율적인가? 런타임 시점에서 테스트 및 디버깅 목적으로 객체의 동작을 분석하거나, 테스트 용도로 사용되면 가장 베스트다. 이는 리플렉션은 테스트 용도로 사용하고 실제 프로그램 개발단에서는 리플렉션을 이용한 로직은 최대한 지양해야 한다는 의..
참조로 전달이란? 함수의 인자로 넘길때는 여러가지 방법이 있다. 1) 값으로 전달 2) 참조로 전달 C++ 로가면, Call by value, Call by reference, Call by Pointer 이렇게 얘기하는 부분들이 있는데, 쉽게 이야기하면 넘기기 직전의 값을 복사해서 값만 넘길 것이냐, 주소까지 완전 복사해서 이 인자를 수정하면 넘겼던 주체까지 수정될 수 있게 하느냐 그 차이다. C# 에서 값을 참조로 변경해서 넘기기 위해서는 out, ref 키워드를 정해서 작성해야 한다. 작성 예는 아래와 같다. public void Test_Func(ref int a){ a += 10; } static void Main(){ int test_A = 10; Test_Func(ref test_A); } ..
[문제] 왕비를 피해 일곱 난쟁이들과 함께 평화롭게 생활하고 있던 백설공주에게 위기가 찾아왔다. 일과를 마치고 돌아온 난쟁이가 일곱 명이 아닌 아홉 명이었던 것이다. 아홉 명의 난쟁이는 모두 자신이 "백설 공주와 일곱 난쟁이"의 주인공이라고 주장했다. 뛰어난 수학적 직관력을 가지고 있던 백설공주는, 다행스럽게도 일곱 난쟁이의 키의 합이 100이 됨을 기억해 냈다. 아홉 난쟁이의 키가 주어졌을 때, 백설공주를 도와 일곱 난쟁이를 찾는 프로그램을 작성하시오. [입력] 아홉 개의 줄에 걸쳐 난쟁이들의 키가 주어진다. 주어지는 키는 100을 넘지 않는 자연수이며, 아홉 난쟁이의 키는 모두 다르며, 가능한 정답이 여러 가지인 경우에는 아무거나 출력한다. [출력] 일곱 난쟁이의 키를 오름차순으로 출력한다. 일곱 난..
[문제] Given an integer array nums, move all 0's to the end of it while maintaining the relative order of the non-zero elements. Note that you must do this in-place without making a copy of the array. [TC] Example 1: Input: nums = [0,1,0,3,12] Output: [1,3,12,0,0] Example 2: Input: nums = [0] Output: [0] Constraints: 1
[문제] You are given an integer array nums and an integer k. In one operation, you can pick two numbers from the array whose sum equals k and remove them from the array. Return the maximum number of operations you can perform on the array [TC] Example 1: Input: nums = [1,2,3,4], k = 5 Output: 2 Explanation: Starting with nums = [1,2,3,4]: - Remove numbers 1 and 4, then nums = [2,3] - Remove number..
[문제] You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]). Find two lines that together with the x-axis form a container, such that the container contains the most water. Return the maximum amount of water a container can store. Notice that you may not slant the container. [TC] Example 1: Inp..
[문제] Given two strings s and t, return true if s is a subsequence of t, or false otherwise. A subsequence of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., "ace" is a subsequence of "abcde" while "aec" is not). [TC] Example 1: Input: s = "abc", t = "ahb..
[문제] Given an array of characters chars, compress it using the following algorithm: Begin with an empty string s. For each group of consecutive repeating characters in chars: If the group's length is 1, append the character to s. Otherwise, append the character followed by the group's length. The compressed string s should not be returned separately, but instead, be stored in the input character..