Java 8 has Optional<T>
which is nice way to declare optional types as described here.
Is there an equivalent way to that in C# ?
Asked
Active
Viewed 2.2k times
7

user2864740
- 60,010
- 15
- 145
- 220

AymenDaoudi
- 7,811
- 9
- 52
- 84
-
3http://msdn.microsoft.com/en-us/library/1t3y8s4s.aspx Nullable types. – Jeroen Vannevel Jun 15 '14 at 17:10
-
@JeroenVannevel: Nullable types work only for value types, as far as I know – AymenDaoudi Jun 15 '14 at 17:12
-
For reference types you could possibly use code contracts as per this article http://blog.coverity.com/2013/11/20/c-non-nullable-reference-types/#.U53fXy29KSM – Daniel Dutton Jun 15 '14 at 18:05
-
1Since C# 8.0 there are [nullable reference types](https://learn.microsoft.com/en-us/dotnet/csharp/nullable-references). – Ruben9922 Oct 23 '19 at 10:53