Define a primitive data type: Difference between revisions

Added C#
(Omit from J (J does not allow type definitions -- only allows definitions of things like classes and objects))
(Added C#)
Line 191:
===Other libraries or implementation specific extensions===
As of February 2009 no open source libraries to do this task have been located.
=={{header|C sharp|C#}}==
<lang csharp>public class TinyInt
{
private const int minimalValue = 1;
private const int maximalValue = 10;
 
private readonly int value;
 
private TinyInt(int i)
{
if (minimalValue > i || i > maximalValue)
{
throw new System.ArgumentOutOfRangeException();
}
value = i;
}
 
public static implicit operator int(TinyInt i)
{
return i.value;
}
 
public static implicit operator TinyInt(int i)
{
return new TinyInt(i);
}
}</lang>
=={{header|C++}}==
{{works with|g++}}
Anonymous user