# Specify Variable Size

Is there an easy way to specify the variable size and still use them as variables more specifically for the .NETLink?

Something like the following I am thinking.

t = Int[2];


and then the variable could only be set to unsigned int values as an example.

Anoter example I want i = unsignedChar[3] to be exactly 0 to 255 when you assign values to it. So i = 156 would either throw an error or overflow.

ClearAll[t];
t /: Set[t, whatever : Except[_Integer]] := $Failed ]  You can use whatever patter you wish. t = 2; t  2 t = "test"  $Failed

• my question is not very clear but Micheal is close to what I am after. Essentially. I want i = unsignedChar[3] to be exactly 0 to 255 when you assign values to it. So i = 156 would either throw an error or overflow. – William Jan 17 '17 at 16:24
• So how would I automate the following so if I do t=unsignedChar[2]; it would expand ClearAll[t]; Module[{out = True}, t /: Set[t, n_Integer] /; out := Block[{out = False}, If[0 <= n && n <= 255, t = n, False ] ]; ];t=2; – William Jan 22 '17 at 2:37