| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 16 | 17 | 18 | 19 | 20 | 21 | 22 |
| 23 | 24 | 25 | 26 | 27 | 28 | 29 |
| 30 |
Tags
- File
- chashtag
- algorithm
- .net
- convert
- Visual Studio
- tls
- WPF
- C#
- log
- Github
- string
- ListView
- programmers
- coding-test
- nullable
- git
- logging
- Microsoft
- commit
- mysql
- windows10
- 코딩테스트
- dotNET
- Binding
- csharp
- windows
- IValueConverter
- Coding
- Process
Archives
- Today
- Total
목록nullable (2)
CHashtag
결론만 알려드리겠습니다. int defaultValue = 999; int? nullableInt = null; // int wrongResult = (int)nullableInt; // System.InvalidOperationException here int result = nullableInt.GetValueOrDefault(defaultValue); // 999 감사합니다.
C#
2021. 2. 18. 00:50
결론부터 알려드리겠습니다. DateTime? dateTime = null; if(dateTime != null) { Console.WriteLine(dateTime.Value.ToString("yyyy")); } 또는 DateTime? dateTime = null; Console.WriteLine(dateTime?.ToString("yyyy")); 을 사용하면 됩니다. 기본적으로 DateTime 형식에는 null이 지원되지 않습니다. 이때 타입 뒤에 "?" 를 붙임으로써 nullable형식으로 만들 수 있는데 이때 DateTime의 ToString함수가 overloading을 제공하지 않습니다. 이때 Nullable의 Value라는 속성을 이용하면 됩니다. 하지만 Value가 null일 경우 System..
C#
2020. 8. 10. 17:36