일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- coding-test
- log
- 코딩테스트
- convert
- Process
- Visual Studio
- chashtag
- csharp
- Microsoft
- Github
- .net
- Binding
- windows
- Coding
- ListView
- commit
- IValueConverter
- git
- logging
- dotNET
- File
- nullable
- C#
- mysql
- algorithm
- WPF
- string
- programmers
- tls
- windows10
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