4

I want to use an Option type in C#.
Are there any good alternatives for an Option type in C# like 'T option in F#, Option[A] in Scala, or Optional<T> in Java 8?

I know that F#'s 'T option can be used in C# like an external library (FSharp.Core), but I think that is... Well, is it preferable to do so? There may be some problems like name conflicts.

Jodrell
  • 34,946
  • 5
  • 87
  • 124
Naetmul
  • 14,544
  • 8
  • 57
  • 81
  • 1
    Take a look here: http://stackoverflow.com/questions/16199227/optional-return-in-c-net – Bambuk Apr 06 '16 at 11:31
  • 1
    I think the short answer is no. The long answer is in the duplicate. – Jodrell Apr 06 '16 at 11:39
  • Nothing exists like that currently. There are some "workarounds" but they aren't satisfactory. The best you can do is go over to the Roslyn github and open a feature request https://github.com/dotnet/roslyn Check the Wiki for discussions about future language features https://github.com/dotnet/roslyn/wiki This is where new features are being incubated/discussed/worked on. –  Apr 06 '16 at 11:41

1 Answers1

-4

I think you are looking for Nullable types, which are similar to Javas Optional.

Georg Patscheider
  • 9,357
  • 1
  • 26
  • 36