G
Guest
With generics in .NET 2, there are certain scenarios in which using
System.Void would be useful:
TReturnType MyFunction<TReturnType>()
{
return default(TReturnType);
}
Above is a simple function that would allow me to make a generic method that
would return any type I instanciate the method with. But what if I wanted to
return void? Well, I will just call MyFunction<System.Void>(). Unfortunately,
the compiler issues an error saying System.Void isn't accessible in C#.
What is the reasoning behind this? Why are we not allowed to use System.Void
in C#?
System.Void would be useful:
TReturnType MyFunction<TReturnType>()
{
return default(TReturnType);
}
Above is a simple function that would allow me to make a generic method that
would return any type I instanciate the method with. But what if I wanted to
return void? Well, I will just call MyFunction<System.Void>(). Unfortunately,
the compiler issues an error saying System.Void isn't accessible in C#.
What is the reasoning behind this? Why are we not allowed to use System.Void
in C#?