|
|
|
|
|
by noblethrasher
4153 days ago
|
|
But, structs pay a very small runtime penalty, if at all, right? The verbosity will be mostly ameliorated with primary constructor. I propose going further by allowing programmers to annotate constructors so that they can be used as user-defined conversion operators. Thus, the aforementioned code could become something like: public struct GreaterThanFive implicit (int n)
{
readonly int n = n;
if(n <= 5)
throw new ArgumentException("n must be greater than 5");
}
|
|
I meant the verbosity of having to create a custom type for each kind of restriction, versus some inline "int n [n > 5]" notation.