I want to have a List of a type Regex. But the list can have None (or null).
So I'd like the syntax List<Regex|Null>
or something similar.
- There is a blog post here that has the same concept.
But I'm hoping there may be something baked into C# I am overlooking.
Python 3 has Optional. Does C# have anything like that?
I did see something about using a question mark here. But it didn't give an example that made sense to me.
new T?(x)
I have seen:
- a post entitled "Discriminated Unions" here that sort of hits the point of what I am after.
- Also this entitled "Multiple generic Types in one List" one.
I also think there are often Union classes for this kind of thing, having seen similar SO posts
What would be the simplest C# code to define such a Typed generic List, and add either null
or a Regex
to it?