


string str = "Hello, World!";
int index = str.IndexOf("World");
이 코드는 str 문자열에서 "World" 문자열의 첫 번째 인덱스를 찾아 index 변수에 저장합니다.
string str = "Hello, World!";
string newStr = str.Replace("World", "Universe");
이 코드는 str 문자열에서 "World" 문자열을 "Universe" 문자열로 대체한 새로운 문자열 newStr을 생성합니다.
string input = Console.ReadLine();
string[] numbers = input.Split(' ');
이러면 input이 10, 20 이면 10, 20이 따로 numbers에 담기게된다
int currentExp = 1200;
int requiredExp = 2000;
string result = (currentExp >= requiredExp) ? "레벨업 가능" : "레벨업 불가능";
Console.WriteLine(result);
//결과 레벨업 불가능
↑삼항 연산자
int PlayerScore = 100;
string PlayerRank = string.Empty;
// 인트 나누기 인트는 나머지값을 없앰.
// EX) 95/ 10 = 9 (나머지값을 없애므로)
switch (PlayerScore / 10)
{
case 10:
case 9:
PlayerRank = "Diamond";
break;
case 8:
PlayerRank = "Platinum";
break;
default:
PlayerRank = "Iron";
break;
}
Console.WriteLine(PlayerRank);
//결과 Diamond
위 코드를 보면 playerscore / 10을 해서 값이 10이 되었는데,
그러면 case10에 해당되게 되고, break가 걸리지 않는이상 아래로 주욱 내려가다가
case9에 해당하는 diamond를 받는다.
char input = Console.ReadLine()[0];
if (input >= 'a' && input <= 'z' || input >= 'A' && input <= 'Z')
{
Console.WriteLine("알파벳입니다.");
}
else
{
Console.WriteLine("알파벳이 아닙니다.");
}
조건문에 문자를 넣는것도 가능했다.
int i;
for (i = 0; i < 10; i += 2)
{
}
for문 안에서 사용된 i는 for문이 끝나면 끝인데
for밖에서 한번 선언해주면 i가 저장된다
for도 while처럼무한루프가 가능하다
for(;;)
float의 값은 엄청 작은 수라서 Unity버전과 상황에 따라 값이 변할수 있어서 조심해야 한다고 한다.

상등비교를 주의해야하고 오류가 발생할수있다.
문자 등을 특정한 데이터 형태로 변경하는 것을 인코딩이라고 하며, 대표적으로 ASCII가 있다.
배열과는 다르게 크기가 가변적이다
배열과 비슷한 자료 구조를 가지고있다
List
list는 가변적인 크기를 갖는 배열
list를 생성할 때는 list에 담을 자료형을 지정
List<int> numbers = new List<int>(); // 빈 리스트 생성
numbers.Add(1); // 리스트에 데이터 추가
numbers.Add(2);
numbers.Add(3);
numbers.Remove(2); // 리스트에서 데이터 삭제
foreach(int number in numbers) // 리스트 데이터 출력
{
Console.WriteLine(number);
}
Dictionary
Dictionary<string, int> scores = new Dictionary<string, int>(); // 빈 딕셔너리 생성
scores.Add("Alice", 100); // 딕셔너리에 데이터 추가
scores.Add("Bob", 80);
scores.Add("Charlie", 90);
scores.Remove("Bob"); // 딕셔너리에서 데이터 삭제
foreach(KeyValuePair<string, int> pair in scores) // 딕셔너리 데이터 출력
{
Console.WriteLine(pair.Key + ": " + pair.Value);
}
Stack<int> stack1 = new Stack<int>(); // int형 Stack 선언
// Stack에 요소 추가
stack1.Push(1);
stack1.Push(2);
stack1.Push(3);
// Stack에서 요소 가져오기
int value = stack1.Pop(); // value = 3 (마지막에 추가된 요소)
Queue<int> queue1 = new Queue<int>(); // int형 Queue 선언
// Queue에 요소 추가
queue1.Enqueue(1);
queue1.Enqueue(2);
queue1.Enqueue(3);
// Queue에서 요소 가져오기
int value = queue1.Dequeue(); // value = 1 (가장 먼저 추가된 요소)
HashSet<int> set1 = new HashSet<int>(); // int형 HashSet 선언
// HashSet에 요소 추가
set1.Add(1);
set1.Add(2);
set1.Add(3);
// HashSet에서 요소 가져오기
foreach (int element in set1)
{
Console.WriteLine(element);
}

배열과 리스트의 차이점
1줄요약 : 리스트를 무분별하게 사용하지 말라
void PrintMessage(string message)
{
Console.WriteLine("Message: " + message);
}
void PrintMessage(int number)
{
Console.WriteLine("Number: " + number);
}
// 메서드 호출
PrintMessage("Hello, World!"); // 문자열 매개변수를 가진 메서드 호출
PrintMessage(10); // 정수 매개변수를 가진 메서드 호출
재귀 호출 개념과 동작 원리
재귀 호출은 메서드가 자기 자신을 호출하는 것을 의미합니다.
재귀 호출은 호출 스택에 호출된 메서드의 정보를 순차적으로 쌓고, 메서드가 반환되면서 스택에서 순차적으로 제거되는 방식으로 동작합니다.
void CountDown(int n)
{
if (n <= 0)
{
Console.WriteLine("Done");
}
else
{
Console.WriteLine(n);
CountDown(n - 1); // 자기 자신을 호출
}
}
// 메서드 호출
CountDown(5);
재귀 호출의 활용과 주의점
Console.WriteLine("숫자 맞추기 게임을 시작합니다. 1에서 100까지의 숫자 중 하나를 맞춰보세요");
Random random = new Random();
int guess = 0;
int number = random.Next(1,101);
int attempts = 0;
while (number != guess)
{
Console.Write("숫자를 입력하세요: ");
guess = int.Parse(Console.ReadLine());
if (guess < number)
{
Console.WriteLine("너무 작습니다");
attempts++;
}
if (guess > number)
{
Console.WriteLine("너무 큽니다!");
attempts++;
}
}
Console.WriteLine($"축하합니다! {attempts}번만에 숫자를 맞추었습니다.");