... | @@ -394,6 +394,51 @@ null 값 확인 용도의 if문을 대폭 줄일 수 있다. |
... | @@ -394,6 +394,51 @@ null 값 확인 용도의 if문을 대폭 줄일 수 있다. |
|
Person 속성 : Name, Age
|
|
Person 속성 : Name, Age
|
|
Press any key to continue . . .
|
|
Press any key to continue . . .
|
|
|
|
|
|
|
|
* **Dictionary 타입의 인덱스 초기화**
|
|
|
|
```cs
|
|
|
|
var weekends1 = new Dictionary<int, string>
|
|
|
|
{
|
|
|
|
{ 0, "Sunday"},
|
|
|
|
{ 1, "Monday"},
|
|
|
|
{ 1, "Monday"}, // 불가능 weekends1.Add(1, "Monday")를 호출하기 때문에 예외발생
|
|
|
|
};
|
|
|
|
|
|
|
|
var weekends2 = new Dictionary<int, string>
|
|
|
|
{
|
|
|
|
[0] = "Sunday",
|
|
|
|
[6] = "Saturday",
|
|
|
|
[6] = "Monday", // 인텍서 방식의 코드로 변경되기 때문에 가능
|
|
|
|
};
|
|
|
|
```
|
|
|
|
|
|
|
|
* **예외 필터**
|
|
|
|
```cs
|
|
|
|
static void Main(string[] args)
|
|
|
|
{
|
|
|
|
string filePath = @"C:\Users\Jaehyun\Desktop\null.txt";
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
string txt = File.ReadAllText(filePath);
|
|
|
|
}
|
|
|
|
catch (FieldAccessException e) when (Log(e))
|
|
|
|
{
|
|
|
|
Console.WriteLine("실행됨");
|
|
|
|
}
|
|
|
|
catch (FileNotFoundException e) when (filePath.IndexOf("Users") != -1)
|
|
|
|
{
|
|
|
|
Console.WriteLine("실행됨");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static bool Log(FieldAccessException e)
|
|
|
|
{
|
|
|
|
Console.WriteLine(e.ToString());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
* **catch/finally 블록 내에서 await 사용 가능**
|
|
* **collection 초기화 구문에 extend method로 정의한 Add 지원**
|
|
* **collection 초기화 구문에 extend method로 정의한 Add 지원**
|
|
```cs
|
|
```cs
|
|
public class NaturalNumber : IEnumerable
|
|
public class NaturalNumber : IEnumerable
|
... | | ... | |