In Delphi (or any Pascal) you can declare sub-range type so if you try assign value from outside allowed range, you would get compiler error.
var
i: 1..8;
begin
i := 8; // i := 9 would not work
Can this be done in C#? I can imagine creating custom struct, something like SubrangeType<byte>
but I'm looking for something builtin.
EDIT: xanatos's and DavidHeffernan's comments gave me idea for more specific question. Subrange checking in Delphi is available both in run-time and compile-time. Implementing that on run-time would be possible in C# using custom struct but would it be possible to implement that checking on compile-time in C#?