Enhanced C#
Language of your choice: library documentation
|
@void.Value
represents the sole value of System.Void
(called "void" in C#).
More...
@void.Value
represents the sole value of System.Void
(called "void" in C#).
.NET unfortunately treats void as something that is not a real type; for example you cannot use new void()
or default(void)
in C#. This was a dumb decision because it means that some generic code must be duplicated for void and non-void types. A good example is the fact that when you have a Dictionary<TKey,TVal>, TVal cannot be void, so you cannot use Dictionary(string,void)
to express the idea of "a set of strings with no associated values". The HashSet<T> class uses a completely separate implementation and cannot just be an alias for Dictionary{T,void}
(actually they could share implementations using a dummy type like this one, but unfortunately .NET made another dumb decision that all types must consume at least one byte, so HashSet
sharing code with Dictionary
would make HashSet
less efficient.)
Defining a @void type allows you to use it when it makes conceptual sense, although we cannot avoid .NET's requirement to waste at least one byte.
Public static fields | |
static readonly void | Value = new @void() |
Public Member Functions | |
override string | ToString () |