목록언어/C# (31)
Machineboy空

오버플로우(Overflow)란?변수는 데이터를 담는 그릇과 같다.그릇에 용량 이상의 물을 담으면 넘치는 것 처럼, 변수에도 데이터 형식의 크기를 넘어선 값을 담으면 넘친다.각 데이터 형식의 최대값을 넘어가는 데이터를 저장하려고 할 때 발생uint a = uint.MaxValue; // 4294967295a = a + 1; // 0wrap around under these circumstances. 오버플로 되면 다시 최소값부터 시작되어 할당된다. checked 키워드정수형의 overflow를 감지하고 예외를 발생시키는 것int one = 1;checked{ int expr = int.MaxValue + one; // OverflowException is thrown}int expr2 = c..
프로퍼티(Property)의 이점객체지향 언어라면 모름지기 '은닉성'을 표현할 수 있어야 한다.객체의 데이터가 의도하지 않게 오염되는 것을 막아야 하기 때문. 클래스를 작성하다가 필드를 public으로 선언해버리고 싶은 충동이 들 때가 있다.여차하면 의도하지 않게 데이터가 오염될 수 있다. 프로퍼티를 이용하면 은닉성과 편의성을 모두 잡을 수 있다.프로퍼티(Property)의 기능을 메소드로 표현한다면?class MyClass{ private int myField; // 값은 private로 은닉성을 지키면서 public int GetMyField() // get과 set은 public으로 편의성을 가진다. { return myField; } public..
프로그램이 비정상적인 상황을 만났을 때 이를 처리하는 예외 처리예외(Exception) : 프로그래머가 생각한 시나리오에서 벗어나는 사건예외 처리(Exception Handling) : 예외가 프로그램의 오류나 다운으로 이어지지 않도록 적절하게 처리하는 것예외를 처리하지 못해 죽는 프로그램은 아무리 기능이 많아도 신뢰할 수 없다.System.Exception 클래스와 throwall exeptions have System.Exception class as their base typecontains Message, reason for the exception being thrown모든 예외는 System.Exception 클래스를 상속하고, 사람이 읽을 수 있는 형태의 예외 원인 메시지를 던진다.예) Ou..

is 연산자지정된 형식과 호환되는지 확인int i = 27;object iBoxed = i;Console.WriteLine(isBoxed is int); // TrueConsole.WriteLine(isBoxed is long); // Falseas 연산자지정된 형식으로 변환IEnumerable numbers = new List() {10,20,30};IList indexable = numbers as IList;if(indexable != null){ Console.WriteLine(indexable[0] + indexable[indexable.Count -1]) // 10 + 30 = 40}예제using System;using System.Collections;using System.Collect..

문제요약Yacht 게임의 점수 도출 시스템을 만들어라. https://exercism.org/tracks/csharp/exercises/yacht/dig_deeper Dig Deeper into Yacht in C# on ExercismExplore different approaches and videos on how to solve Yacht in C#.exercism.org난이도Medium풀이 포인트LINQ를 공부해보자!https://machineboy0.tistory.com/328 LINQ풀이에 LINQ가 너무 많이 나와서 한 번은 제대로 공부하고 지나가야겠다.LINQ에 익숙해지면 마치 간단한 영어 문장을 만들 듯 데이터 질의 코드를 작성할 수 있다.LINQ란?Language INtegrated ..

Attribute란?way to decorate a declaration to associate metadata to: a class, a method, an enum, a field, a property or any other supported declarations코드의 메타데이터를 나타내는 데 사용되는 선언적 태그.클래스, 메서드, 속성, 이벤트, 필드 등과 같은 다양한 프로그래밍 요소에 추가 정보를 제공할 때 사용[Class]class MyClass{ [Field] int myField;} Attribute의 역할only associates additional structured informationdoes not modify its behaviorto change how its tar..
상수와 변수변수상수담고 있는 데이터를 얼마든지 변경할 수 있는 메모리 공간담긴 데이터를 절대 바꿀 수 없는 메모리 공간 값을 바꾸지 말아야 할 변수를 건드리는 실수를 할 수도 있기 때문에 상수를 선언한다.컴파일러가 소스 코드를 컴파일할 때, 프로그래머의 실수를 잡아 알려주고, 결국 프로그램 버그도 줄여준다.열거형 : 여러 개의 상수a fixed set of named constants(an enumeration)type-safe way of interacting with numeric constants, limiting the available values to a pre-defined set.종류는 같지만 다른 값을 갖는 상수를 선언해야 할 때 열거형을 사용한다.열거형 값 할당열거형의 값을 지정하지 ..